////////////////////////////////////////////////////////////////////////////////
//  COPYRIGHT (C) 2010 TELECOM DIGITAL MEDIA ("TDMEDIA").
//  ALL RIGHTS RESERVED.
//
//  THIS IS CONFIDENTIAL AND PROPRIETARY INTELLECTUAL PROPERTY OWNED BY AND
//  CREATED ON BEHALF OF TDMEDIA. ANY FORM OF DISTRIBUTION, COPY,
//  MODIFICATION WITHOUT THE WRITTEN CONSENT FROM TDMEDIA IS STRICTLY
//  PROHIBITED.
////////////////////////////////////////////////////////////////////////////////
package cc.telecomdigital.tdstock.activity.groups.monitor;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import cc.telecomdigital.tdstock.ColorRefreshTask;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.CustomizeDialog;
import cc.telecomdigital.tdstock.DBHelper;
import cc.telecomdigital.tdstock.DefaultClickHandler;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.LightStreamerHandlerInterface;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.RefreshHandlerInterface;
import cc.telecomdigital.tdstock.StringUtils;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Http.H_CODE;
import cc.telecomdigital.tdstock.Http.HttpSuperClassStockBaseActivity;
import cc.telecomdigital.tdstock.Http.Services.HttpAppInfo;
import cc.telecomdigital.tdstock.Http.Services.H_HttpServiceRequest.H_UserClient_HttpRequest_Result;
import cc.telecomdigital.tdstock.Services.LS_SubscriptionItem;
import cc.telecomdigital.tdstock.Services.LS_UserClient.ILS_UserClient_Response;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.BaseActivity;
import cc.telecomdigital.tdstock.activity.groups.ForeignExchangeGroup;
import cc.telecomdigital.tdstock.activity.groups.IndexGroup;
import cc.telecomdigital.tdstock.activity.groups.MonitorGroup;
import cc.telecomdigital.tdstock.activity.groups.MoreGroup;
import cc.telecomdigital.tdstock.activity.groups.StockGroup;
import cc.telecomdigital.tdstock.activity.groups.foreignexchange.ForeignExchangeActivity;
import cc.telecomdigital.tdstock.activity.groups.index.IndexActivity;
import cc.telecomdigital.tdstock.activity.groups.index.IndexCOPListActivity;
import cc.telecomdigital.tdstock.activity.groups.monitor.util.BookMarkUtil;
import cc.telecomdigital.tdstock.activity.groups.monitor.util.MonitorUtil;
import cc.telecomdigital.tdstock.activity.groups.monitor.util.SaveBookMarkAsyncTask;
import cc.telecomdigital.tdstock.activity.groups.more.MetalActivity;
import cc.telecomdigital.tdstock.activity.groups.more.MoreActivity;
import cc.telecomdigital.tdstock.activity.groups.more.OilQuoteActivity;
import cc.telecomdigital.tdstock.activity.groups.more.Top20StockListActivity;
import cc.telecomdigital.tdstock.activity.groups.stock.CurrentStockInfoActivity;
import cc.telecomdigital.tdstock.adapter.MonitorListItemAdapter;
import cc.telecomdigital.tdstock.adapter.MonitorViewHolder;
import cc.telecomdigital.tdstock.model.ForeignExchangeInfo;
import cc.telecomdigital.tdstock.model.HolidayInfo;
import cc.telecomdigital.tdstock.model.IndexFuturesInfo;
import cc.telecomdigital.tdstock.model.IndexInfo;
import cc.telecomdigital.tdstock.model.IntlMetalInfo;
import cc.telecomdigital.tdstock.model.OilInfo;
import cc.telecomdigital.tdstock.model.StockInfo;
import cc.telecomdigital.tdstock.model.Top20StockInfo;
import cc.telecomdigital.tdstock.model.WorldFuturesInfo;
import cc.telecomdigital.tdstock.model.WorldIndexDelayInfo;
import cc.telecomdigital.tdstock.model.WorldIndexInfo;
import cc.telecomdigital.tdstock.utils.Futures;
import cc.telecomdigital.tdstock.view.SunFlowerView;
import cc.telecomdigital.tdstock.view.TouchListView;

import com.lightstreamer.ls_client.UpdateInfo;

public class PortfolioActivity extends HttpSuperClassStockBaseActivity implements RefreshHandlerInterface, /*CdrSender, */ILS_UserClient_Response
{
	@Override
	public Handler getHandler()
	{
		if (((ITDLApplication) getApplicationContext()).isExitApp())
		{
			return null;
		}
		return _messageHandler;
	}

	protected static final String				TAG		= PortfolioActivity.class.getSimpleName();
	private String 							cameFromTag = null;
	private String 							lastTag = null;
	//Zor 2011-12-07
//	private static final String				VOLUME			= "Volume";
//	private static final String				TURNOVER			= "Turnover";
	private Button							_editMonitorBtn;
	private Button							_stockClassBtn;
//	private Button							_toolBtnReturn;//Zor 2011-12-07
//	private Button							_toolBtnTop20stock;//Zor 2011-12-07

	private ViewGroup						_fornews;
	private Button							_dj;
	private Button							_f;

//	private TextView						_topBarTitle;

//Zor 2011-12-07
//	private TextView						_listViewColumn_4;
//	private TextView						_listViewColumn_5;

	private ViewGroup						_listViewTitle;

	private   TouchListView	_listView;
	private boolean						_isEditing;
	private  boolean			_isCustomerSubscribedItems = false;

	private  MonitorListItemAdapter		_monitor_item_Adapter;
	private  Vector<MonitorViewHolder>	_monitorList;
	private  Vector<MonitorViewHolder>	_dropList			= new Vector<MonitorViewHolder>();
	
	
	private static  String                 IDENTIFIER_0 =  PortfolioActivity.class.getSimpleName() + "00";
	private static  String                 IDENTIFIER_1 =  PortfolioActivity.class.getSimpleName() + "01";
	private static  String                 IDENTIFIER_2 =  PortfolioActivity.class.getSimpleName() + "02";  //it is different from tdstock4
	private static  String                 IDENTIFIER_3=   PortfolioActivity.class.getSimpleName() + "03"; //it is different from tdstock4
	private static  String                 IDENTIFIER_3_0=   PortfolioActivity.class.getSimpleName() + "03_0"; //it is different from tdstock4
	private static  String                 IDENTIFIER_4_0=   PortfolioActivity.class.getSimpleName() + "04_0";
	private static  String                 IDENTIFIER_4_1=   PortfolioActivity.class.getSimpleName() + "04_1";
	private static  String                 IDENTIFIER_4_2=   PortfolioActivity.class.getSimpleName() + "04_2";
	private static  String                 IDENTIFIER_4_3=   PortfolioActivity.class.getSimpleName() + "04_3";
	private static  String                 IDENTIFIER_5 =  PortfolioActivity.class.getSimpleName() + "05";
	private static  String                 IDENTIFIER_6=   PortfolioActivity.class.getSimpleName() + "06";
//	private static  String                 IDENTIFIER_7=   PortfolioActivity.class.getSimpleName() + "07";
	
	
	private LightStreamerHandlerInterface _callbackHandler00;
	private LightStreamerHandlerInterface _callbackHandler01;
	private LightStreamerHandlerInterface _callbackHandler02;
	private LightStreamerHandlerInterface _callbackHandler03;
	private LightStreamerHandlerInterface _callbackHandler03_0;  //no use now
	private LightStreamerHandlerInterface _callbackHandler04_0;
	private LightStreamerHandlerInterface _callbackHandler04_1;
	private LightStreamerHandlerInterface _callbackHandler04_2;
	private LightStreamerHandlerInterface _callbackHandler04_3;
	private LightStreamerHandlerInterface _callbackHandler05;
	private LightStreamerHandlerInterface _callbackHandler06;
	//private LightStreamerHandlerInterface _callbackHandler07;
	
	
	
	//private AppWillExitListenerReceiver  _appExitReceiver;

	//	 private Button _addBtn;
	//	 private Button _delBtn;
	private DBHelper						_dbHelper;
	//	 private TextView _stockCodeTV;
	//	 private Spinner _stockCodeSP;
	private SharedPreferences				_prefsStockCode;

	//private OnItemLongClickListener _onItemLongClickListener;
	private OnItemClickListener				_onItemClickListener;
	//	 private ImageView _toolbutton_options;

	//private static StreamerTimeoutHandler		_streamerTimeoutHandler;

//	private boolean						_isTradingTime;
	//private CdrHelper						_cdrHelper;

	private Context						_context;

	private final static String COP_TAG = "9";
	private  static long   runTimeOnLightStreamer = 1L;  //ms
	private final long   LEAST_INTERVAL_OF_MS  = 500L;     //ms
	private final boolean					usingBlinkColumn	= true;
	private final int						blinkTime			= 300;
	private final int						INFO_CONTENT_UPDATE	= 1;
//	private final boolean					usingDummy		= true;
	private long							lastRunntimeInOnResume		= 1l;						//use this to avoid the onResume execute twice at the same time
	private long							lastRunntimeInOnPause		= 1l;						//use this to avoid the onPausee execute twice at the same time

	private Handler						UIUpdater			= new Handler()
														{
															@Override
															public void handleMessage(
																	Message msg)
															{
																switch (msg.what)
																{
																	case INFO_CONTENT_UPDATE:
																		{
																			String identity;
																			int    index;
	
																			identity = (String) msg.obj;
																			index = msg.arg1;
																			if ((identity != null) && (index != -1))
																				PortItemUpdate(identity, index);
																		}
																		break;
																}
															}
														};

	/** Find MonitorViewHolder item index, based on the name provided
	 *  if the iItemName is not found, a -1 will be return;																	
	 * @param iItemName
	 * @return
	 */
	private int FindListItem(String iItemName)
	{
		synchronized(_listView)
		{
			int      childCount;
			View     tmpHolder;
			TextView textViewObj;

			childCount = _listView.getChildCount();
			
			for (int index = 0; index < childCount; index++)
			{
				tmpHolder = _listView.getChildAt(index);
				if (tmpHolder == null)
					continue;

				textViewObj = (TextView)(tmpHolder.findViewById(R.id.monitor_item_code));
				if (textViewObj == null)
					continue;
			
				if (textViewObj.getText().toString().equals(iItemName) == false)					
					continue;
				
				return index;
			}
			
			return -1;
		}
	}
			
	/** Update MonitorViewHolder Item based on index from the list. 
	 *  If it is not found, it will not applied
	 * @param itemName
	 * @param iIndex
	 */
	private void PortItemUpdate(String itemName, int iIndex)
	{
		synchronized (_listView)
		{
			View tmpHolder;
			
			if (iIndex == -1)
				return;
			
			try
			{
				tmpHolder = _listView.getChildAt(iIndex);
				
				final View parentHolder = tmpHolder;

				Animation animatAction = AnimationUtils.loadAnimation(
						_context, R.anim.just_delay);
				animatAction.setDuration(blinkTime);
				animatAction.setAnimationListener(new AnimationListener()
				{
					@Override
					public void onAnimationEnd(Animation animation)
					{
						parentHolder.setBackgroundResource(R.drawable.monitor_row_bgstates);
					}

					@Override
					public void onAnimationRepeat(Animation animation)
					{ }

					@Override
					public void onAnimationStart(Animation animation)
					{ }
				});
				parentHolder.setBackgroundColor(getResources().getColor(R.color.blue));
				parentHolder.setAnimation(animatAction);
				animatAction.startNow();
				parentHolder.invalidate();				
			}
			catch(Exception e)
			{
				TDStockLog.e(TAG, "PortItemUpdate: " + e.toString());
			}
			return;
			

		}
	}

	@Override
	public void onCreate(final Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.portfolio);
//		_streamerTimeoutHandler = new StreamerTimeoutHandler(this,
//				_messageHandler);
		//_cdrHelper = new CdrHelper(this, _messageHandler);
		//	         initToolButtons();
		//	         resetMinHeightOnWorkCenter();
		//DefaultClickHandler handler = new DefaultClickHandler(this);

		_context = this;
		// "期指Futures"，"上証SSEI" set Adapter
		initFuturesAndSSEIAdapterType();
		
		// instance = this;
		_isEditing = false;
		_isCustomerSubscribedItems = false;

		_listViewTitle = (ViewGroup) findViewById(R.id.transparent_panel);

//		_topBarTitle = (TextView) findViewById(R.id.top_bar_title);
		_fornews = (ViewGroup) findViewById(R.id.fornews);
		_dj = (Button) findViewById(R.id.btn_dj);
		_f = (Button) findViewById(R.id.btn_f);

		_dj.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog
						.d(TAG,
								"close current activity and forwarding to the previous");

				Intent intent = new Intent(getApplicationContext(),
						MonitorNewsDjActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				
				SwitchForwardActivity(MonitorNewsDjActivity.class, intent);
			}

		});
		_f.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG, "close current activity and forwarding to the previous");
				Intent intent = new Intent(getApplicationContext(), MonitorNewsFActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchForwardActivity(MonitorNewsFActivity.class, intent);
			}
		});

//		_listViewColumn_4 = (TextView) findViewById(R.id.monitor_column_4);
//		_listViewColumn_5 = (TextView) findViewById(R.id.monitor_column_5);
		_listView = (TouchListView) findViewById(R.id.monitor_list);

		_onItemClickListener = new OnItemClickListener()
		{
			@Override
			public void onItemClick(AdapterView<?> parent, View iView,
					int iIndex, long iArgs)
			{
				int objId;

				objId = parent.getId();
				switch (objId)
				{
					case R.id.monitor_list:
						if (iIndex != -1 && (!_isEditing))
						{
							TDStockLog.d(TAG, "item click");
							forwardToDestActivity(iIndex);
						}
						break;
				}
			}
		};

		_listView.setOnItemClickListener(_onItemClickListener);

		/*  _onItemLongClickListener =  new  OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> parent,
					View view, int position, long id) {
				 if(position != -1 && ( !_isEditing)) {
						TDStockLog.d(TAG, "item Longclick");
						forwardToDestActivity(position);
					   return true;
				 }
				return false;
			}
		  	  
		   };*/

		_listView.setDropListener(onDrop);
		_listView.setRemoveListener(onRemove);
		_monitorList = new Vector<MonitorViewHolder>();
		_monitor_item_Adapter = new MonitorListItemAdapter(LayoutInflater
				.from(this), _monitorList);
		//Adjust Size when display changes?          
		_listView.setAdapter(_monitor_item_Adapter);

		_editMonitorBtn = (Button) findViewById(R.id.monitor_edit);
		_editMonitorBtn.setOnClickListener(new EditRowClickHandler(this));

//Zor 2011-12-07
//		_toolBtnReturn = (Button) findViewById(R.id.more_returnbtn);
//		_toolBtnReturn.setOnClickListener(new OnClickListener()
//		{
//			@Override
//			public void onClick(View v)
//			{
//				TDStockLog
//						.d(TAG,
//								"close current activity and forwarding to the previous");
//				/*Intent intent =new Intent(getApplicationContext(),MoreActivity.class);
//				intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//				startActivity(intent);*/
//
//				((ITDLApplication) getApplicationContext()).putString(
//						CommonDefn.ACTIVITY_CAME_FROM_KEY, ""); //modified by haibo on 2011-07-07 , reset the come from tag when leave the page
//
//				Intent intent = new Intent(getApplicationContext(),
//						MoreActivity.class);
//				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
//				/*View viewIntent = MoreGroup.group.getLocalActivityManager()
//						.startActivity(
//								MoreActivity.class.getSimpleName(),
//								intent).getDecorView();
//				MoreGroup.group.setContentView(viewIntent); // modify by ouyangzhihui 2011-05-16
//*/			
//
//				SwitchTabHostActivity( 4, MoreGroup.GetActivityGroupHostControl(), MoreActivity.class ,intent);
//			
//			}
//
//		});
//
//		_toolBtnTop20stock = (Button) findViewById(R.id.top20stock);
//		_toolBtnTop20stock.setOnClickListener(new OnClickListener()
//		{
//			@Override
//			public void onClick(View v)
//			{
//				/*Intent intent =new Intent(getApplicationContext(),Top20StockListActivity.class);
//				intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//				startActivity(intent);*/
//
//				Intent intent = new Intent(getApplicationContext(),
//						Top20StockListActivity.class);
//				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
//			/*	View viewIntent = MoreGroup.group.getLocalActivityManager()
//						.startActivity(
//								Top20StockListActivity.class
//										.getSimpleName(), intent)
//						.getDecorView();
//				MoreGroup.group.setContentView(viewIntent); // modify by ouyangzhihui 2011-05-16
//*/
//				//SwitchForwardActivity(Top20StockListActivity.class, intent);
//				SwitchTabHostActivity( 4, MoreGroup.GetActivityGroupHostControl(), Top20StockListActivity.class ,intent);						
//			}
//
//		});

		_stockClassBtn = (Button) findViewById(R.id.monitor_class);
		_stockClassBtn.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(getApplicationContext(),
						StockSectorActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchForwardActivity(StockSectorActivity.class, intent);
			}

		});

		_dbHelper = new DBHelper(this);

		//by zhengan
//		Button _toolbutton_soccer = (Button) findViewById(R.id.toolbutton_soccer);//足球
//		Button _toolbutton_horserace = (Button) findViewById(R.id.toolbutton_horserace);//赛马
//
//		_toolbutton_soccer.setOnClickListener(
//
//		new View.OnClickListener()
//		{
//
//			@Override
//			public void onClick(View v)
//			{
//				forwardToSoccerActivity();
//			}
//		});
//
//		_toolbutton_horserace.setOnClickListener(
//
//		new View.OnClickListener()
//		{
//
//			@Override
//			public void onClick(View v)
//			{
//				forwardToHorseraceActivity();
//			}
//		});
		isChangeModeType = false;
	}
	public static boolean isChangeModeType = false;
	/*-----------------by ouyangzhihui 2011-08-24-------------------*/
	protected static String _indexFuturesAdapter = IndexFuturesInfo.ADAPTER;
	protected static String _indexSSEIAdapter = WorldIndexDelayInfo.ADAPTER;
	
	private void initFuturesAndSSEIAdapterType()
	{
		/* "期指"2 (account login && svcPlan=1) || activeCode login */
		if((((ITDLApplication)getApplicationContext()).getIsRealtimeFutures() && ((ITDLApplication)getApplicationContext()).getModeType() == CommonDefn.ModeType.ACCOUNTLOGIN) 
				|| ((ITDLApplication)getApplicationContext()).getModeType() == CommonDefn.ModeType.ACTIVECODE)
		{
			// 實時數據
			_indexFuturesAdapter = IndexFuturesInfo.adapter_realtime;
		}
		else
		{
			_indexFuturesAdapter = IndexFuturesInfo.adapter_delay;
		}
		
		/* "上証"5 (account login && svcPlan=1) || activeCode login */
		if((((ITDLApplication)getApplicationContext()).getIsRealtimeSSEI() && ((ITDLApplication)getApplicationContext()).getModeType() == CommonDefn.ModeType.ACCOUNTLOGIN) 
				|| ((ITDLApplication)getApplicationContext()).getModeType() == CommonDefn.ModeType.ACTIVECODE)
		{
			// 實時數據
			_indexSSEIAdapter = WorldIndexInfo.ADAPTER;
		}
		else
		{
			_indexSSEIAdapter = WorldIndexDelayInfo.ADAPTER;
		}
	}
	/*-----------------by ouyangzhihui 2011-08-24-------------------*/

	@Override
	protected void onDestroy()
	{
		if (_dbHelper != null)
		{
			this._dbHelper.cleanup();
			_dbHelper = null;
			TDStockLog.i(GetIdentity(), "onDestroy: _dbHelper");
		}			
		
//		if(((ITDLApplication) getApplicationContext()).getCdrSender() == null )  
//		{
//			/*if (_cdrHelper != null)
//			{
//				TDStockLog.d(TAG, "ready to send cdr1!");
//				 this.sendCdrInfo();
//			}*/
//		}
//		else {
//			TDStockLog.d(TAG, "ready to send cdr1!");
//		}
		

		/*if (_streamerTimeoutHandler != null)
		{
			_streamerTimeoutHandler.killCounter();
			_streamerTimeoutHandler = null;
		}*/

		super.onDestroy();
	}

	@Override
	protected void onRestart()
	{
		if (_dbHelper == null)
		{
			_dbHelper = new DBHelper(this);
		}
		
		if(_listView != null)
			_listView.setVisibility(View.VISIBLE);

		super.onRestart();
	}

	/**
	 *  I don't know why this method execute twice sometime(it happens at the time when i unlock the screen for this page)
	 */
	@Override
	protected void onResume()
	{
		TDStockLog.d(TAG, "onResume-------------------->_monitorList size : " + _monitorList.size());
		super.SetExectuHttpRequestOnResume(false);
		super.onResume();
		String cameFromString = ((ITDLApplication) getApplicationContext()).getString(CommonDefn.ACTIVITY_CAME_FROM_KEY);
		// 先處理當前頁面該做的事 [負責：1）自選 2）版塊]
		TDStockLog.d(TAG, "cameFromTag="+cameFromString);
		if(cameFromString != null && !"".equals(cameFromString) && cameFromString.matches(CommonDefn.SECTOR_REG))
		{
			TDStockLog.d(TAG, "cameFromTag...版塊");
			// 版塊數據
			cameFromTag = cameFromString;
		}
		else
		{
			TDStockLog.d(TAG, "cameFromTag...自選");
			// 自選股票
			cameFromTag = TAG;
		}
		
		
		if(isChangeModeType)
		{
			// "期指Futures"，"上証SSEI" set Adapter
			initFuturesAndSSEIAdapterType();
			isChangeModeType = false;
		}
		
		resetTitle();
		resetTopToolBtn(cameFromTag);
		resetTable();
		
		
	/*	if (!SystemInfo.isNetworkingConnected(this))
		{
			clearSunFlower(); //by ouyangzhihui 2011-08-11
			new CustomizeDialog(getMyOwnContext(), getResources().getString(
					R.string.info), getResources().getString(
					R.string.networking_disconnect_tips)).show();
			return;
		}*/
		
		// do nothing if there's no any subscribed item     
		if (TAG.equals(cameFromTag) && ((ITDLApplication) getApplicationContext()).getDataMode() == CommonDefn.DataMode.Delay)
		{
			int customerId = 1;
			List<String[]> items = _dbHelper.getSubscribeItemsByUserId(customerId);
			if(items == null || items.size() < 1)
			{
				//clearSunFlower(); //by ouyangzhihui 2011-08-11
				return;
			}
		}

		
		TDStockLog.d(TAG, "On Resume executed!");
//		((ITDLApplication) getApplicationContext()).setCdrSender(this);
		TDStockLog.d(TAG, "parent:" + this.getParent().getClass().getSimpleName());
//		registerAppExitReceiver();
		if (System.currentTimeMillis() - lastRunntimeInOnResume < 1000l
				&& lastRunntimeInOnResume != 1l)
		{
			for (MonitorViewHolder holder : _monitorList)
			{
				holder.isEditable = _isEditing;
			}
			_monitor_item_Adapter.notifyDataSetChanged();
			TDStockLog.d(TAG, "don't execute twice during a short term in onResume!");
			return;
		} //don't execute twice during a short term
		lastRunntimeInOnResume = System.currentTimeMillis();

		//	    	 TDStockLog.d(TAG, String.format("On Resume executed!, and instance number: %d", Activity.getInstanceCount()));
		

		if (_dbHelper == null)
		{
			_dbHelper = new DBHelper(this);
		}

		if (_dropList != null)
		{
			_dropList.clear();
		}


		//remove the icon appear in the monitor
		//TDStockLog.v(TAG, _iconTip+" , "+_iconContent);
		if (_iconTip != null && mWindowManager != null)
		{
			mWindowManager.removeViewImmediate(_iconTip);
			_iconTip = null;
		}

		if (_isEditing)
		{
			_isEditing = false;
			//Reset Item to non-editing mdode
			_listView.SetEditingMode(_isEditing);
		}
		TDStockLog.d(TAG, "onResume2------------>_monitorList size : " + _monitorList.size());
		connectLightStreamerExt(getMyOwnContext());
		TDStockLog.d(TAG, "onResume3------------>_monitorList size : " + _monitorList.size());
	}

	@Override
	protected void onStart()
	{
		super.onStart();
		if (_dbHelper == null)
			_dbHelper = new DBHelper(this);
	}

	private void resetTable()
	{
		if(TAG.equals(cameFromTag) && cameFromTag.equals(lastTag)) 
		{
			TDStockLog.d(TAG, "calling:" + this.getCallingPackage() + '.' + this.getCallingActivity());
			TDStockLog.d(TAG, "resetTable------------>_monitorList size : " + _monitorList.size());
			_monitor_item_Adapter.notifyDataSetChanged();
			TDStockLog.d(TAG, "don't clear  the old rows if the old content is customer subscribed!");
			return;
		}
		
		_listView.setClickable(false);
		
		TDStockLog.d(TAG, "ready to clear the old rows!");
		
		_monitorList.clear();
		_monitor_item_Adapter.notifyDataSetChanged();
		
		TDStockLog.d(TAG, "clear the old rows successfully!!");
		
		_listView.setClickable(true);
	}

	private void updateAdapter(String code, String[] otherFields, String adapter)
	{
		TDStockLog.d(TAG, "MonitorUpdate=>" + code);
		
		if(_isEditing || _isInBackground) 
		{
			TDStockLog.d(TAG, "don't allow to update the adapte yet for it is editing!");
			return;
		}
		boolean isChange = true;
		boolean isUpdating = false;
		for (MonitorViewHolder monitorViewHolder : _monitorList)
		{
			if (code.equals(monitorViewHolder.itemCode.getText().toString())  &&  adapter.equalsIgnoreCase(monitorViewHolder.adapter))
			{
				/*if(Futures.TypeName_Str.contains(code))
				{
					if(!monitorViewHolder.adapter.equals(adapter))
						continue;
				}*/
				
				isUpdating = true;
				monitorViewHolder.isEditable = _isEditing;
				monitorViewHolder.isTop20orSector =  ! _isCustomerSubscribedItems;
				//monitorViewHolder.adapter = adapter;
				
				/*Zor Testing code*/
				/*if(!"".equals(monitorViewHolder.itemNet.getText().toString().trim()) && !"--".equals(monitorViewHolder.itemNet.getText().toString().trim()) && !"---".equals(monitorViewHolder.itemNet.getText().toString().trim()))
				{
					otherFields[0] = monitorViewHolder.itemName.getText().toString().trim();
					otherFields[1] = monitorViewHolder.itemValue.getText().toString().trim();
					otherFields[2] = monitorViewHolder.itemNet.getText().toString().trim();
					otherFields[3] = monitorViewHolder.itemNetPercentage.getText().toString().trim();
				}*/
				/*if(monitorViewHolder.itemName != null && monitorViewHolder.itemValue != null && monitorViewHolder.itemNet != null 
						&& monitorViewHolder.itemNetPercentage != null)
				{
					String itemName = otherFields[0];
					String lastItemName = monitorViewHolder.itemName.getText().toString().trim();
					String itemValue = otherFields[1];
					String lastItemValue = monitorViewHolder.itemValue.getText().toString().trim();
					String itemNet = otherFields[2];
					String lastItemNet = monitorViewHolder.itemNet.getText().toString().trim();
					String itemNetPercentage = otherFields[3];
					String lastItemNetPercentage = monitorViewHolder.itemNetPercentage.getText().toString().trim();
					
					String tmp = "MonitorUpdate: " + lastItemName + "," + itemName + "," + lastItemValue + "," + itemValue + "," + lastItemNet + "," + itemNet + "," + lastItemNetPercentage + "," + itemNetPercentage;
					
					// value not change
					try
					{
						if(itemName != null && itemValue != null && itemNet != null && itemNetPercentage != null 
								&& itemName.equals(lastItemName) && itemValue.equals(lastItemValue) && itemNet.equals(lastItemNet) 
								&& itemNetPercentage.equals(lastItemNetPercentage))
						{
							isChange = false;
							tmp += " --" + isChange;
							TDStockLog.d(TAG, tmp);
							break;
						}
						else
						{
							tmp += " --" + isChange;
							TDStockLog.d(TAG, tmp);
						}
					}
					catch(Exception e)
					{
						e.printStackTrace();
					}
				}*/
				
				if (monitorViewHolder.itemName == null)
				{
					TDStockLog.d(TAG, "generated a new view on itemName");
					monitorViewHolder.itemName = new TextView(this);
				}
				monitorViewHolder.itemName.setText(otherFields[0]);

				if (monitorViewHolder.itemValue == null)
				{
					TDStockLog.d(TAG, "generated a new view on itemValue");
					monitorViewHolder.itemValue = new TextView(this);
				}
				monitorViewHolder.itemValue.setText(otherFields[1]);
				if (monitorViewHolder.itemNet == null)
				{
					TDStockLog.d(TAG, "generated a new view on itemNet");
					monitorViewHolder.itemNet = new TextView(this);
				}
				monitorViewHolder.itemNet.setText(otherFields[2]);
				if (monitorViewHolder.itemNetPercentage == null)
				{
					TDStockLog.d(TAG, "generated a new view on itemNetPercentage");
					monitorViewHolder.itemNetPercentage = new TextView(
							this);
				}
				monitorViewHolder.itemNetPercentage.setText(otherFields[3]);
				TDStockLog.d(TAG, String.format(
						"ready to update the item : %s , thread id: %d",
						code, Thread.currentThread().getId()));
				break;
			}
		}

		if (!isUpdating)
		{
			//append a record
			MonitorViewHolder monitorViewHolder = new MonitorViewHolder();
			monitorViewHolder.isEditable = _isEditing;
			monitorViewHolder.isTop20orSector = ! _isCustomerSubscribedItems;
			
			monitorViewHolder.adapter = adapter;
			
			monitorViewHolder.itemCode = new TextView(this);
			monitorViewHolder.itemCode.setText(code);

			monitorViewHolder.itemName = new TextView(this);
			monitorViewHolder.itemName.setText(otherFields[0]);

			monitorViewHolder.itemValue = new TextView(this);
			monitorViewHolder.itemValue.setText(otherFields[1] == null ? "" : otherFields[1]);

			monitorViewHolder.itemNet = new TextView(this);
			monitorViewHolder.itemNet.setText(otherFields[2] == null ? "" : otherFields[2]);

			monitorViewHolder.itemNetPercentage = new TextView(this);
			monitorViewHolder.itemNetPercentage.setText(otherFields[3] == null ? "" : otherFields[3]);
			TDStockLog.d(TAG, "ready to insert the item :" + code);
			_monitorList.add(monitorViewHolder);
		}
		
		_listView.setClickable(false);
		_monitor_item_Adapter.notifyDataSetChanged();
		_listView.setClickable(true);
		
	/*	if(!isChange)
			return;*/
		
		//Change animation after update or a holder is created
		if (usingBlinkColumn)
		{
			Message exMessage;
			int     index;
			
			index = FindListItem(code);
			if (index == -1)
				return;
			
			exMessage = /*new Message();*/ UIUpdater.obtainMessage();
			exMessage.what = INFO_CONTENT_UPDATE;
			exMessage.obj = code;
			exMessage.arg1 = index;
			UIUpdater.sendMessage(exMessage);
		}
	}

	private class CallbackHandlerOnStock implements
		LightStreamerHandlerInterface
	{
		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			if (_isInBackground || _isEditing || !isItemExist(itemName))
			{
				//do nothing  for the monitor is editing.
				return;
			}

			/*
			          if(update.isValueChanged(  StockInfo.NET))
			          {
			*/
			try
			{
				/*
				                    double newValue = Double.parseDouble(update.getNewValue(StockInfo.NET));
				                    String oldValue = update.getOldValue(StockInfo.NET);
				*/
				
				// Just Blink Item, is it fast enough
				// Blink should occur on nominal price change only.
				if (!usingBlinkColumn)
				{
					int Color = CommonDefn.MONITOR_HIGHLIGHT_BACKGROUND_ORANGE;

					ColorRefreshTask refresh = new ColorRefreshTask(
							PortfolioActivity.this, Color, itemName);
					_messageHandler.postDelayed(refresh, 50);
				}
			}
			catch (Exception e)
			{
				TDStockLog.e(TAG, "can't update the status when net is changed!");
				e.printStackTrace();
			}
			//        }

			//Update content
			final String[] fields = new String[4];
			fields[0] = update.getNewValue(StockInfo.STOCKCHISHORTNAME);
//			fields[1] = StringUtils.FormatNumber(StringUtils.ITDLNumber.STOCKPRICE, update.getNewValue(StockInfo.NOMINAL));
			/* 
			          fields[2] =  update.getNewValue(  StockInfo.Net);
			          fields[3] =  update.getNewValue(  StockInfo.NetPercentage);
			*/
//			fields[2] = StringUtils.FormatNumber(StringUtils.ITDLNumber.NET, update.getNewValue(StockInfo.NET));
//			fields[3] = String.format("%s", StringUtils.FormatNumber(StringUtils.ITDLNumber.NETPERCENTAGE, update.getNewValue(StockInfo.NETPERCENTAGE)));

			fields[1] = StringUtils.roundDownFormatToFiveCharsRule(update.getNewValue(StockInfo.NOMINAL));
			fields[2] = StringUtils.formatNumberByNet(update.getNewValue(StockInfo.NET));
			fields[3] = update.getNewValue(StockInfo.NETPERCENTAGE);
			int p = 4;
			try{
				if(Double.parseDouble(fields[3]) > 10)
					p = 5;
			}
			catch(Exception e)
			{
			}
			fields[3] = StringUtils.formatNumberByNetPerectage(fields[3], p);
			//The following is used to update the adapter
			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					//updateRowInTable(itemName, fields);
					updateAdapter(itemName, fields, StockInfo.ADAPTER);
//					//Change animation after update or a holder is created
//					if (usingBlinkColumn)
//					{
//						Message exMessage;
//						int     index;
//						
//						index = FindListItem(itemName);
//						if (index == -1)
//							return;
//						
//						exMessage = /*new Message();*/ UIUpdater.obtainMessage();
//						exMessage.what = INFO_CONTENT_UPDATE;
//						exMessage.obj = itemName;
//						exMessage.arg1 = index;
//						UIUpdater.sendMessage(exMessage);
//					}
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();			
		}
	}

	private class CallbackHandlerOnGold implements LightStreamerHandlerInterface
	{
		private String[]	_itemName;

		public CallbackHandlerOnGold(String[] itemName)
		{
			_itemName = itemName;
		}

		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			if (_isInBackground || _isEditing || !isItemExist(itemName))
			{
				//do nothing  for the monitor is editing.
				return;
			}

			if (!usingBlinkColumn)
			{
				//if(update.isValueChanged( StockInfo.Nominal))
				//{
				ColorRefreshTask refresh = new ColorRefreshTask(
						PortfolioActivity.this,
						CommonDefn.HIGHLIGHT_BACKGROUND_COLOR, itemName);
				_messageHandler.postDelayed(refresh, 50);
				//}
			}

			final String[] fields = new String[4];
			fields[0] = _itemName[itemPos - 1];
			fields[1] = update.getNewValue(IntlMetalInfo.METALLAST);
			/* 
			          fields[2] =  update.getNewValue(  StockInfo.Net);
			          fields[3] =  update.getNewValue(  StockInfo.NetPercentage);
			*/
			fields[2] = CommonDefn.DEFAULT_FIELD_VALUE;
			fields[3] = CommonDefn.DEFAULT_FIELD_VALUE;

			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					//updateRowInTable(itemName, fields);
					updateAdapter(itemName, fields, IntlMetalInfo.ADAPTER);
//					if (usingBlinkColumn)
//					{
//						Message exMessage;
//						int     index;
//						
//						index = FindListItem(itemName);
//						if (index == -1)
//							return;
//						exMessage = /*new Message();*/ UIUpdater.obtainMessage();
//						exMessage.what = INFO_CONTENT_UPDATE;
//						exMessage.obj = itemName;
//						exMessage.arg1 = index;
//						UIUpdater.sendMessage(exMessage);
//					}
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}
	}

//	private class CallbackHandlerOnStockTop20 implements
//		LightStreamerHandlerInterface
//	{
//		public void onUpdate(final int itemPos, final String itemName,
//				final UpdateInfo update)
//		{
//			if (_isInBackground)
//			{
//				return;
//			}
//
//			for (int index = 0; index < Top20StockInfo.RECORD_TOTAL_NUMBER; index++)
//			{
//				final String stockCode = update
//						.getNewValue(Top20StockInfo.STOCK + (index + 1));
//				if (update.isValueChanged(Top20StockInfo.NOMINAL
//						+ (index + 1)))
//				{
//
//					ColorRefreshTask refresh = new ColorRefreshTask(
//							PortfolioActivity.this,
//							CommonDefn.HIGHLIGHT_BACKGROUND_COLOR,
//							stockCode);
//					_messageHandler.postDelayed(refresh, 50);
//
//				}
//
//				final String[] fields = new String[4];
//				fields[0] = update.getNewValue(Top20StockInfo.getFieldName(
//						itemName, Top20StockInfo.RECORD_TOTAL_NUMBER
//								+ index));
//				fields[1] = StringUtils.FormatNumber(
//						StringUtils.ITDLNumber.STOCKPRICE,
//						update.getNewValue(Top20StockInfo.getFieldName(
//								itemName,
//								Top20StockInfo.RECORD_TOTAL_NUMBER * 2
//										+ index)));
//				if(fields[1].indexOf(".") >= 5)
//				{
//					fields[1] = StringUtils.roundDownInteger(fields[1]);
//				}
//				else
//				{
//					fields[1] = StringUtils.roundDownFormatToFiveCharsRule(fields[1]);
//				}
//				/* fields[2] =  update.getNewValue(  StockInfo.Net);
//				 fields[3] =  update.getNewValue(  StockInfo.NetPercentage);*/
//				if (itemName.equals(Top20StockInfo.ITEMS[0]) || itemName.equals(Top20StockInfo.ITEMS[4]))
//				{
//					// % 增
////					fields[2] =/* StringUtils.FormatNumber(StringUtils.ITDLNumber.NET, */
////							update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index));//);
////					
////					fields[3] = /*String.format("%s", StringUtils.FormatNumber(StringUtils.ITDLNumber.NETPERCENTAGE,*/
////							update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index));//));
//					
//					fields[2] = StringUtils.formatNumberByNet(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)));
//					fields[3] = StringUtils.formatNumberByNetPerectage(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)), 5);
//					TDStockLog.d(TAG, "tmp01="+fields[0]+" , "+fields[1]+" , "+fields[2]+" , "+fields[3]);
//				}
//				else if(itemName.equals(Top20StockInfo.ITEMS[1]) || itemName.equals(Top20StockInfo.ITEMS[5]))
//				{
//					// % 减
//					fields[2] = StringUtils.formatNumberByNet(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)));
//					fields[3] = StringUtils.formatNumberByNetPerectage(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)) ,4);
//					TDStockLog.d(TAG, "tmp02="+fields[0]+" , "+fields[1]+" , "+fields[2]+" , "+fields[3]);
//				}
//				else
//				{
//					// K/M/B
////					fields[2] = StringUtils.FormatNumberOnTurnOverOrShareTraded(
////							update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)));
////					fields[3] = StringUtils.FormatNumberOnTurnOverOrShareTraded(
////							update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)));
//					fields[2] = StringUtils.formatNumberByTurnove(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 3 + index)), 1);
//					fields[3] = StringUtils.formatNumberByTurnove(update.getNewValue(Top20StockInfo.getFieldName(itemName, Top20StockInfo.RECORD_TOTAL_NUMBER * 4 + index)), 1);
//					
//					TDStockLog.d(TAG, "tmp03="+fields[0]+" , "+fields[1]+" , "+fields[2]+" , "+fields[3]);
//				}
//				
//				/*String itemNetPerectage = fields[3];
//				itemNetPerectage = itemNetPerectage.substring(0, itemNetPerectage.length()-1);
//				String pix = itemNetPerectage.substring(0, 1);
//				itemNetPerectage = StringUtils.roundDownFormatToNCharsRuleNotAddZero(itemNetPerectage, 5);
//				if(!itemNetPerectage.endsWith("-"))
//				{
//					if(!StringUtils.F.equals(pix))
//					{
//						pix = StringUtils.Z;
//					}
//					itemNetPerectage = pix + itemNetPerectage + "%";
//				}
//				else
//				{
//					itemNetPerectage = "--";
//				}*/
//
//				final Runnable myUpdateResults = new Runnable()
//				{
//					public void run()
//					{
//						//updateRowInTable(itemName, fields);
//						updateAdapter(stockCode, fields,
//								Top20StockInfo.ADAPTER);
//					}
//				};
//
//				new Thread()
//				{
//					public void run()
//					{
//						if (_messageHandler != null)
//							_messageHandler.post(myUpdateResults);
//					}
//				}.start();
//
//			}
//
//		}
//	}
	
	
	//haibo, 2011-08-15, subscribed items in AsyncTask
	public synchronized void onConnectionEstablished()
	{
		TDStockLog.d(TAG, TAG+"------>onConnectionEstablished");
		onConnectionEstablishedEx();
	}

	public synchronized void onConnectionEstablishedEx()
	{	
		
		_isCustomerSubscribedItems = false;
		try
		{
			if(cameFromTag == null) 
			{
				cameFromTag = TAG;
			}
			
			if (CommonDefn.SECTOR_REG.matches(cameFromTag))
			{
				TDStockLog.d(TAG, "cameFromTag=ready to fetch one sector!");

//				new FetchOneSector().execute(cameFromTag);
				SendHttpRequest();

				return;
			}
			else
			{
				final Runnable loadingLocalData = new Runnable()
				{
					public void run()
					{
						int customerId = 1;
						List<String[]> items = _dbHelper.getSubscribeItemsByUserId(customerId);
						
						
						TDStockLog.d(TAG, "loadingLocalData........");
						
						
	
						if (items == null || items.size() < 1)
							return;
	
						for (String[] strings : items)
						{
							TDStockLog.d(TAG, "item---->"+strings[0]);
						}
						
						//啟動太陽花
						startSunFlower(getMyOwnContext());
						
						_isCustomerSubscribedItems = true;
						_monitorList.clear();					
						TDStockLog.d(TAG, "cameFromTag=ready to fetch customer subscribe items!");
						
						List<String> iIdList = new ArrayList<String>();
						List<LS_SubscriptionItem> iItemList = new ArrayList<LS_SubscriptionItem>();
						List<ILS_UserClient_Response> iResponseList  = new ArrayList<ILS_UserClient_Response>();
						
						
						StringBuffer stockItems = null;
						StringBuffer goldInfoItems = null;
						StringBuffer goldNames = null;
	
						StringBuffer indexFuturesItems = null;
						StringBuffer indexFuturesCOPItems = null;
	
						StringBuffer indexItems = null;
						StringBuffer indexNames = null;
						/* "上証SSEI" by ouyangzhihui 2011-08-25 */
						StringBuffer worldIndexDelayRealtimeItems = null;
						StringBuffer worldIndexDelayRealtimeNames = null;
						
						StringBuffer worldIndexItems = null;
						StringBuffer worldIndexNames = null;
	
						StringBuffer worldIndexFuturesItems = null;
	
						StringBuffer worldIndexDelayItems = null;
						StringBuffer worldIndexDelayNames = null;
	
						StringBuffer fxItems = null; //foreign exchange rate ;
	
						boolean isSubscribedOil = false;
						_listView.SetEditingMode(_isEditing);
	
						for (final String[] array : items)
						{
							MonitorViewHolder monitorViewHolder = new MonitorViewHolder();
							monitorViewHolder.isEditable = _isEditing;
							monitorViewHolder.isTop20orSector = false;
							monitorViewHolder.adapter = array[1];
							monitorViewHolder.isCop = (IndexFuturesInfo.ADAPTER + IndexFuturesInfo.COP).equals(monitorViewHolder.adapter );
							monitorViewHolder.itemCode = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemCode.setText(array[0]);
	
							monitorViewHolder.itemName = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemValue = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemNet = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemNetPercentage = new TextView(
									PortfolioActivity.this);
	
							//deal with stock
							if (TextUtils.isDigitsOnly(array[0])
									&& StockInfo.ADAPTER
											.equalsIgnoreCase(array[1]))
							{
								if (stockItems == null)
								{
									stockItems = new StringBuffer();
									stockItems.append(array[0]);
								}
								else
								{
									stockItems.append(",").append(array[0]);
								}
							}
							//deal with metal
							else if (IntlMetalInfo.ADAPTER
									.equalsIgnoreCase(array[1])
									&& !ForeignExchangeInfo.CODE_TO_NAME
											.containsKey(array[0]))
							{
								if (goldInfoItems == null)
								{
									goldInfoItems = new StringBuffer();
									goldInfoItems.append(array[0]);
									goldNames = new StringBuffer();
									goldNames.append(array[2]);
								}
								else
								{
									goldInfoItems.append(",").append(
											array[0]);
									goldNames.append(",").append(array[2]);
								}
	
								monitorViewHolder.itemName.setText(array[2]);
							}
							//deal with index futures
							else if (IndexFuturesInfo.ADAPTER.equalsIgnoreCase(array[1]))
							{
								if (indexFuturesItems == null)
								{
									indexFuturesItems = new StringBuffer(
											array[0]);
								}
								else
								{
									indexFuturesItems.append(",").append(
											array[0]);
								}
	
							}
							//deal with index futures Cop
							else if ((IndexFuturesInfo.ADAPTER+IndexFuturesInfo.COP).equalsIgnoreCase(array[1]))
							{
								if (indexFuturesCOPItems == null)
									indexFuturesCOPItems = new StringBuffer(array[0]);
								else
									indexFuturesCOPItems.append(",").append(array[0]);
							}
							//deal with index 
							else if (IndexInfo.ADAPTER
									.equalsIgnoreCase(array[1]))
							{
								array[2] = array[2].replaceAll("[\n\r]", "")
										.replaceAll("(<br>)|(<BR>)", "").replace("(延遲)", ""); //modified by haibo, 2011-06-23, remove any br tag
								if (indexItems == null)
								{
									indexItems = new StringBuffer(array[0]);
									indexNames = new StringBuffer(array[2]);
								}
								else
								{
									indexItems.append(",").append(array[0]);
									indexNames.append(",").append(array[2]);
								}
								monitorViewHolder.itemName
										.setText(array[2] == null ? ""
												: array[2]);
	
							}
							//deal with  world index("上証SSEI")
							/*--"上証SSEI"-----by ouyangzhihui 2011-08-25-----------*/
							else if ((WorldIndexInfo.ADAPTER + WorldIndexDelayInfo.ADAPTER).equalsIgnoreCase(array[1]))
							{
								array[2] = array[2].replaceAll("[\n\r]", "")
										.replaceAll("(<br>)|(<BR>)", "").replace("(延遲)", ""); //modified by haibo, 2011-06-23, remove any br tag
								
								if (worldIndexDelayRealtimeItems == null)
								{
									worldIndexDelayRealtimeItems = new StringBuffer(
											array[0]);
									worldIndexDelayRealtimeNames = new StringBuffer(
											array[2]);
								}
								else
								{
									worldIndexDelayRealtimeItems.append(",").append(
											array[0]);
									worldIndexDelayRealtimeNames.append(",").append(
											array[2]);
								}
								monitorViewHolder.itemName.setText(array[2] == null ? "" : array[2]);
	//							monitorViewHolder.adapter = array[1];
							}
							//deal with  world index 
							else if (WorldIndexInfo.ADAPTER
									.equalsIgnoreCase(array[1]))
							{
								array[2] = array[2].replaceAll("[\n\r]", "")
										.replaceAll("(<br>)|(<BR>)", "").replace("(延遲)", ""); //modified by haibo, 2011-06-23, remove any br tag
								if (worldIndexItems == null)
								{
									worldIndexItems = new StringBuffer(
											array[0]);
									worldIndexNames = new StringBuffer(
											array[2]);
								}
								else
								{
									worldIndexItems.append(",").append(
											array[0]);
									worldIndexNames.append(",").append(
											array[2]);
								}
								monitorViewHolder.itemName
										.setText(array[2] == null ? ""
												: array[2]);
	
							}
							//deal with  world index futures
							else if (WorldFuturesInfo.ADAPTER
									.equalsIgnoreCase(array[1]))
							{
								array[2] = array[2].replaceAll("[\n\r]", "")
										.replaceAll("(<br>)|(<BR>)", "").replace("(延遲)", ""); //modified by haibo, 2011-06-23, remove any br tag
								if (worldIndexFuturesItems == null)
								{
									worldIndexFuturesItems = new StringBuffer(
											array[0]);
								}
								else
								{
									worldIndexFuturesItems.append(",")
											.append(array[0]);
								}
	
							}
							//deal with  world index  delay
							else if (WorldIndexDelayInfo.ADAPTER
									.equalsIgnoreCase(array[1]))
							{
								array[2] = array[2].replaceAll("[\n\r]", "")
										.replaceAll("(<br>)|(<BR>)", "").replace("(延遲)", ""); //modified by haibo, 2011-06-23, remove any br tag
								if (worldIndexDelayItems == null)
								{
									worldIndexDelayItems = new StringBuffer(
											array[0]);
									worldIndexDelayNames = new StringBuffer(
											array[2].length() >= 5 ? array[2]
													.substring(0, 5)
													: array[2]);
								}
								else
								{
									worldIndexDelayItems.append(",")
											.append(array[0]);
									worldIndexDelayNames
											.append(",")
											.append(
													array[2].length() >= 5 ? array[2]
															.substring(
																	0,
																	5)
															: array[2]);
								}
								monitorViewHolder.itemName.setText(array[2]
										.length() >= 5 ? array[2]
										.substring(0, 5) : array[2]);
	
							}
							//deal with  fx
							else if (ForeignExchangeInfo.ADAPTER
									.equalsIgnoreCase(array[1]))
							{
								if (fxItems == null)
								{
									fxItems = new StringBuffer(array[0]);
								}
								else
								{
									fxItems.append(",").append(array[0]);
								}
								TDStockLog.d(TAG, "have foreign exchange items");
	
							}
							else if (OilInfo.ADAPTER
									.equalsIgnoreCase(array[1]))
							{
								isSubscribedOil = true;
							}
	
							_monitorList.add(monitorViewHolder);
						}
						try
						{
	
							if (stockItems != null)
							{
								
								if( _callbackHandler00  == null) 
								{
									_callbackHandler00 = new CallbackHandlerOnStock();
								}
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( StockInfo.ADAPTER);
									for(String item:stockItems.toString()
											.split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field: StockInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
								/*	IDENTIFIER_0 =   LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_0, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									iIdList.add(IDENTIFIER_0);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);		
									
								}
								/*if (_cdrHelper != null)
								{
									_cdrHelper.startCounter();
								}*/
							}
	
							if (goldInfoItems != null)
							{
								
								if(_callbackHandler01 == null)
								{
									
									_callbackHandler01 = new CallbackHandlerOnGold(
											goldNames
											.toString()
											.split(
													"[,]"));
								}
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( IntlMetalInfo.ADAPTER);
									for(String item:goldInfoItems.toString().split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field:IntlMetalInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
								/*	IDENTIFIER_1 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_1, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									iIdList.add(IDENTIFIER_1);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);		
									
								}
								
							}
	
							if (indexFuturesItems != null)
							{
									if(_callbackHandler03 == null)
									{
										_callbackHandler03 = new CallbackHandlerOnIndexFutures();
									}
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem(/*IndexFuturesInfo.ADAPTER*/_indexFuturesAdapter);
									
									interestItem.SetSubscribeItem(indexFuturesItems.toString().split("[,]"));
									interestItem.SetSubscribeSchema(IndexFuturesInfo.MONITOR_FIELDS);
									
//									for(String item:indexFuturesItems.toString().split("[,]"))
//										interestItem.AddSubscribeItem(item);
//									for(String field:IndexFuturesInfo.MONITOR_FIELDS)
//										interestItem.AddSubscribeSchema(field);
						
									iIdList.add(IDENTIFIER_3);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
								
							}
							
							if (indexFuturesCOPItems != null)
							{
								if(_callbackHandler02 == null)
									_callbackHandler02 = new CallbackHandlerOnCOP();
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem(IndexFuturesInfo.adapter_realtime);
									
									interestItem.SetSubscribeItem(indexFuturesCOPItems.toString().split("[,]"));
									
									interestItem.AddSubscribeSchema(IndexFuturesInfo.MM);
									interestItem.AddSubscribeSchema(IndexFuturesInfo.COP);
									
//									for(String item:indexFuturesItems.toString().split("[,]"))
//										interestItem.AddSubscribeItem(item);
//									for(String field:IndexFuturesInfo.MONITOR_FIELDS)
//										interestItem.AddSubscribeSchema(field);
						
									iIdList.add(IDENTIFIER_2);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
							}
	
							if (indexItems != null)
							{
								 if(_callbackHandler04_0 == null)
								 {
									 _callbackHandler04_0 = new LightStreamerHandlerOnIndex(
												indexNames
												.toString()
												.split(
														"[,]"),
										IndexInfo.ADAPTER);
								 }
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( IndexInfo.ADAPTER);
									for(String item: indexItems.toString()
											.split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field:IndexInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
									/*IDENTIFIER_4_0 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_4_0, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									iIdList.add(IDENTIFIER_4_0);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
								
								
							}
							/*--"上証SSEI"-----by ouyangzhihui 2011-08-25-----------*/
							if (worldIndexDelayRealtimeItems != null)
							{
								if(_callbackHandler04_3 == null)
								 {
									 _callbackHandler04_3 = new LightStreamerHandlerOnIndex(
												worldIndexDelayRealtimeNames.toString().split("[,]"),
										_indexSSEIAdapter, "true");
								 }
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem(_indexSSEIAdapter);
									for(String item: worldIndexDelayRealtimeItems.toString().split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field:WorldIndexInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
									
									iIdList.add(IDENTIFIER_4_3);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
							}
							/*-------by ouyangzhihui 2011-08-25-----------*/
							if (worldIndexItems != null)
							{
							
								 if(_callbackHandler04_1 == null)
								 {
									 _callbackHandler04_1 = 	new LightStreamerHandlerOnIndex(
												worldIndexNames
												.toString()
												.split(
														"[,]"),
										WorldIndexInfo.ADAPTER);
								 }
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( WorldIndexInfo.ADAPTER);
									for(String item: worldIndexItems.toString().split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field: WorldIndexInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
									/*IDENTIFIER_4_1 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_4_1, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									iIdList.add(IDENTIFIER_4_1);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
								
								
								
							}
	
							if (worldIndexFuturesItems != null)
							{
							
								if(_callbackHandler03 == null)
								{
									_callbackHandler03 = new CallbackHandlerOnIndexFutures();
								}
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( WorldFuturesInfo.ADAPTER);
									for(String item: worldIndexFuturesItems.toString().split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field: WorldFuturesInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
									/*IDENTIFIER_3 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_3, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									
									iIdList.add(IDENTIFIER_3_0);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
									TDStockLog.d(TAG, "worldIndexFutures items is ready for subscribtion, and items is:" + worldIndexFuturesItems.toString());
								}
								
								
								
							}
	
							if (worldIndexDelayItems != null)
							{
								
								 if(_callbackHandler04_2 == null)
								 {
									 _callbackHandler04_2 = 	new LightStreamerHandlerOnIndex(
												worldIndexDelayNames
												.toString()
												.split(
														"[,]"),
										WorldIndexDelayInfo.ADAPTER);
								 }
								 
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( WorldIndexDelayInfo.ADAPTER);
									for(String item:  worldIndexDelayItems.toString().split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field: WorldIndexDelayInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
									/*IDENTIFIER_4_2 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_4_2, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									iIdList.add(IDENTIFIER_4_2);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
								
							}
	
							if (fxItems != null)
							{
									if(_callbackHandler05 == null)
									{
										_callbackHandler05 = new LightStreamerHandlerOnFX();
									}
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( ForeignExchangeInfo.ADAPTER);
									for(String item:  fxItems.toString().split("[,]"))
										interestItem.AddSubscribeItem(item);
									for(String field: ForeignExchangeInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
									/*IDENTIFIER_5 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_5, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									
									iIdList.add(IDENTIFIER_5);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
								
								
								
								
								TDStockLog
										.d(TAG,
												"ready to enter  into callback for fx");
							}
	
							if (isSubscribedOil)
							{
								 if(_callbackHandler06 == null)
								 {
									 _callbackHandler06 = new LightStreamerHandlerOnOil();
								 }
								
								{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( OilInfo.ADAPTER);
									for(String item:  OilInfo.SUBSCRIBE_ITEMS_CODE)
										interestItem.AddSubscribeItem(item);
									for(String field: OilInfo.MONITOR_FIELDS)
										interestItem.AddSubscribeSchema(field);
						
									/*IDENTIFIER_6 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_6, interestItem,PortfolioActivity.this)) {
										
									}*/
									
									
									iIdList.add(IDENTIFIER_6);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}
								
								
								
								TDStockLog
										.d(TAG,
												"ready to enter  into callback for oil");
							}
	
							if (((ITDLApplication) getApplicationContext())
									.getDataMode() != CommonDefn.DataMode.Delay)
							{
								/*if( _callbackHandler07 == null)
								{
									_callbackHandler07 = new CallbackHandlerOnSyncTradingTime();
								}*/
								/*{
									LS_SubscriptionItem interestItem = new LS_SubscriptionItem( HolidayInfo.ADAPTER);
									for(String item:  HolidayInfo.SUBSCRIBE_ITEMS)
										interestItem.AddSubscribeItem(item);
									
									interestItem.AddSubscribeSchema(HolidayInfo.FIELD_1);
						
									IDENTIFIER_7 = LSGetUniqueID();
									if (LightStreamerSubscribeItem(IDENTIFIER_7, interestItem,PortfolioActivity.this)) 
									
									iIdList.add(IDENTIFIER_7);
									iItemList.add(interestItem);
									iResponseList.add(PortfolioActivity.this);
								}*/
								
								
								
							}
	
							startCdrCounter();
							
							TDStockLog.d(TAG, "cameFromTag= LightStreamerSubscribeItemsInBatch...自選》"+iItemList.size());
							TDStockLog.d(TAG, TAG+"--------->item size"+_monitorList.size());
							LightStreamerSubscribeItemsInBatch(iIdList, iItemList, iResponseList);
	
						}
						
						catch (Exception e)
						{
							handleLightStreamerException(e);
						}
	
					}
				};
	
				/*new Thread()
				{
					public void run()
					{
						if (_messageHandler != null)
							_messageHandler.post(loadingLocalData);
					}
				}.start();*/
				
				new Thread()
				{
					public void run()
					{

						boolean isDelayMode = (((ITDLApplication) getApplicationContext())
								.getDataMode() == CommonDefn.DataMode.Delay);

						if (_messageHandler != null)
						{
							// _messageHandler.post(myUpdateResults);

							if (isDelayMode)
							{
								_messageHandler.post(loadingLocalData);
							}
							else
							{
/*								// if(!isDelayMode&&MonitorUtil.items==null){
								List<String[]> items = MonitorUtil
										.getInstance()
										.getItems(
												PortfolioActivity.this);
								if (items == null)
								{
									return;
								}
								MonitorUtil.getInstance().updateItem(
										items);
								// }
								_messageHandler
										.post(new LoadingServerData(
												items));*/
								
								GetMonitorItemDataFromServer();
							}

						}
						else
						{

						}
					}
				}.start();
				
				
			}	
		}
		catch (Exception e)
		{
			e.printStackTrace();
			TDStockLog.e(TAG, "cameFromTag="+ (e.getMessage() == null ? "unknown exception happened in onResume!" : e.getMessage()));
			handleLightStreamerException(e);
		}
		
		if (!((ITDLApplication) getApplicationContext()).isAdShowed())
		{
			((ITDLApplication) getApplicationContext()).setAdShowed(true);
			startAdAnim();
		}
	}

	
	
	
	
	private class EditRowClickHandler extends DefaultClickHandler
	{
		EditRowClickHandler(Context context)
		{
			super(context);
		}

		@Override
		public void onDefaultAction()
		{
			if (_toast != null)
				_toast.cancel();

			if (_editMonitorBtn.getText().toString().equals(
					getResources().getString(R.string.monitor_finish)))
			{
				//ready to save to the database;
				int totalmodifiedRecord = _monitorList.size()
						+ _dropList.size();
				if (totalmodifiedRecord >= 1)
				{
					String[] items = new String[totalmodifiedRecord];
					String[] adapter = new String[totalmodifiedRecord];
					int[] index = new int[totalmodifiedRecord];
					int[]type=new int[totalmodifiedRecord];
					int item = 0;

					if (((ITDLApplication) getApplicationContext()).getModeType() == CommonDefn.ModeType.DELARY)
					{

						for (MonitorViewHolder holder : _monitorList)
						{
							items[item] = holder.itemCode.getText().toString();
							adapter[item] = holder.adapter;
							if ("SSE1".equals(items[item])
									|| "SS300".equals(items[item])
									|| "SSEA".equals(items[item])
									|| "SSEB".equals(items[item]))
							{
								adapter[item] = WorldIndexInfo.ADAPTER
										+ WorldIndexDelayInfo.ADAPTER;
							}
							TDStockLog.d(TAG, "1 item=" + items[item]
									+ " , adapter=" + adapter[item]);
							index[item] = item + 1;
							item++;
						}

						for (MonitorViewHolder holder : _dropList)
						{
							items[item] = holder.itemCode.getText()
									.toString();
							adapter[item] = holder.adapter;
							if ("SSE1".equals(items[item])
									|| "SS300".equals(items[item])
									|| "SSEA".equals(items[item])
									|| "SSEB".equals(items[item]))
							{
								adapter[item] = WorldIndexInfo.ADAPTER + WorldIndexDelayInfo.ADAPTER;
							}
							TDStockLog.d(TAG, "2 item=" + items[item]
									+ " , adapter=" + adapter[item]);
							index[item] = -1; //as a mark will delete the record
							item++;
						}
						int customerId = ((ITDLApplication) getApplicationContext())
								.getUserId(-1);
						boolean result = _dbHelper.updateSubscribeItems(
								customerId, items, adapter, index);
						TDStockLog.d(TAG,
								"save to subscription and  the result is "
										+ (result ? " success"
												: "failure"));
					}
					else
					{
						for (MonitorViewHolder holder : _monitorList)
						{
							items[item] = holder.itemCode.getText()
									.toString();
							adapter[item] = holder.adapter;
							if ("SSE1".equals(items[item])
									|| "SS300".equals(items[item])
									|| "SSEA".equals(items[item])
									|| "SSEB".equals(items[item]))
							{
								adapter[item] = WorldIndexInfo.ADAPTER+ WorldIndexDelayInfo.ADAPTER;
							}
							TDStockLog.d(TAG, "1 item=" + items[item]
									+ " , adapter=" + adapter[item]);
							type[item] = holder.type;
							item++;
						}
						List<String[]> lists = new ArrayList<String[]>();
						for (int i = 0; i < index.length; i++)
						{
							if(items[i] == null)
							{
								continue;
							}
							
							String[] temp = new String[2];
							temp[0] = items[i];
							temp[1] = type[i] + "";
							lists.add(temp);
						}
						new SaveBookMarkAsyncTask(PortfolioActivity.this,
								MonitorUtil.getInstance(), "", lists)
								.execute();
					}
					

				}
			}
			else
			{
				try
				{
					//showToast(PortfolioActivity.this, 0, getResources().getString(R.string.monitor_edit_drag_tips));
					showToast(PortfolioActivity.this, 0);
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}

			_isEditing = !_isEditing;
			TDStockLog.d(TAG, "isEditing =  "
					+ (_isEditing ? " true" : "false"));
			_editMonitorBtn.setText(_isEditing ? R.string.monitor_finish
					: R.string.monitor_edit);
			_listView.SetEditingMode(_isEditing);
			for (MonitorViewHolder holder : _monitorList)
			{
				holder.isEditable = _isEditing;
			}
			_monitor_item_Adapter.notifyDataSetChanged();
			TDStockLog.d(TAG,
					"monitor_item_Adapter.notifyDataSetChanged! +  list size: "
							+ _monitorList.size());

		}
	}

	

	public void updateBackground(Object handlerId, int color)
	{
		int childCount = _listView.getChildCount();
		for (int index = 0; index < childCount; index++)
		{
			if (_listView.getChildAt(index) instanceof RelativeLayout)
			{
				RelativeLayout tmpHolder = (RelativeLayout) _listView.getChildAt(index);
				Object itemCode	     = tmpHolder.findViewById(R.id.monitor_item_code);
				
				if (itemCode != null)
				{
					if (((TextView) itemCode).getText().toString().equals(
							handlerId))
					{
						TextView itemValue = (TextView) tmpHolder
								.findViewById(R.id.monitor_item_value);
						TextView netValue = (TextView) tmpHolder
								.findViewById(R.id.monitor_item_net);
						TextView netPercentageValue = (TextView) tmpHolder
								.findViewById(R.id.monitor_item_netpercentage);
						if (itemValue != null && netValue != null
								&& netPercentageValue != null)
						{
							if (color <= 0)
							{
								itemValue.setBackgroundDrawable(null);
								itemValue.postInvalidate();
								netValue.setBackgroundDrawable(null);
								netValue.postInvalidate();
								netPercentageValue
										.setBackgroundDrawable(null);
								netPercentageValue.postInvalidate();
							}
							else
							{
								itemValue.setBackgroundColor(color);
								itemValue.postInvalidate();
								netValue.setBackgroundColor(color);
								netValue.postInvalidate();
								netPercentageValue
										.setBackgroundColor(color);
								netPercentageValue.postInvalidate();
							}
						}
						break;
					}
				}
			}
		}
	}

	private TouchListView.DropListener		onDrop	= new TouchListView.DropListener()
											{
												@Override
												public void drop(
														int from,
														int to)
												{
													MonitorViewHolder item = _monitorList
															.get(from);
													_monitorList
															.remove(item);
													_monitorList
															.add(
																	to,
																	item);
													_listView
															.invalidateViews();
												}
											};

	private TouchListView.RemoveListener	onRemove	= new TouchListView.RemoveListener()
											{
												@Override
												public void remove(
														int which)
												{
													_dropList
															.add(_monitorList
																	.get(which));
													_monitorList
															.remove(_monitorList
																	.get(which));
													_listView
															.invalidateViews();
												}

											};


	private synchronized void resetTopToolBtn(String cameFromTag)
	{
		// 自選（show button: 編輯，賽馬，足球... 版塊）
		if(TAG.equals(cameFromTag))
		{
			// show edit button
			_editMonitorBtn.setVisibility(View.VISIBLE);
			_editMonitorBtn.setText(R.string.monitor_edit);
		}
		else // 版塊數據（show button: 賽馬，足球...版塊） 
		{
			// hide edit button
			_editMonitorBtn.setVisibility(View.GONE);
		}
//		_topBarTitle.setVisibility(View.GONE);
		_fornews.setVisibility(View.VISIBLE);
		
//Zor 2011-12-07
		//restore the column name of list view;
//		_listViewColumn_4.setText(R.string.net);
//		_listViewColumn_5.setText(R.string.net_percentage);
//
//		String cameFrom = ((ITDLApplication) getApplicationContext())
//				.getString(CommonDefn.ACTIVITY_CAME_FROM_KEY);
//		TDStockLog.d(TAG, cameFrom == null ? "come from unknown page!"
//				: "came from " + cameFrom);
//		if (cameFrom == null || "".equals(cameFrom.trim())
//				|| this.getClass().getSimpleName().equals(cameFrom))
//		{
//			_editMonitorBtn.setVisibility(View.VISIBLE);
//			_editMonitorBtn.setText(R.string.monitor_edit);
//			_stockClassBtn.setVisibility(View.VISIBLE);
////			_toolBtnReturn.setVisibility(View.GONE);
////			_toolBtnTop20stock.setVisibility(View.GONE);
//			/*   _editMonitorBtn.postInvalidate();
//			   _stockClassBtn.postInvalidate();
//			   _toolBtnReturn.postInvalidate();
//			   _toolBtnTop20stock.postInvalidate();*/
//			//resetAdapter(_isEditing);
//		}
//		else
//		{
//			if(!isEditable()) {
//				_editMonitorBtn.setVisibility(View.GONE);
//			}
//			
//		
//			//	               _editMonitorBtn.postInvalidate();
//			//  resetAdapter(true);  //is  coming from other page
//		}
//
//		if (MoreActivity.class.getSimpleName().equals(cameFrom))
//		{
////			_toolBtnReturn.setVisibility(View.VISIBLE);
////			_toolBtnReturn.setText(R.string.more);
////			_toolBtnTop20stock.setVisibility(View.VISIBLE);
//			_stockClassBtn.setVisibility(View.GONE);
//			/*  _editMonitorBtn.postInvalidate();
//			  _stockClassBtn.postInvalidate();
//			  _toolBtnReturn.postInvalidate();
//			  _toolBtnTop20stock.postInvalidate();*/
//		}
//		else
//		{
////			_toolBtnTop20stock.setVisibility(View.GONE);
//			_stockClassBtn.setVisibility(View.VISIBLE);
//			/* _toolBtnTop20stock.postInvalidate();
//			 _stockClassBtn.postInvalidate();*/
//		}
//
//		if (StockSectorActivity.class.getSimpleName().equals(cameFrom))
//		{
//			_editMonitorBtn.setVisibility(View.VISIBLE);
//			//	               _editMonitorBtn.postInvalidate();
//		}
//
//		if (cameFrom != null
//				&& cameFrom.matches(CommonDefn.STOCK_LIST_TOP20_REG))
//		{
////			_toolBtnTop20stock.setVisibility(View.VISIBLE);
//			_stockClassBtn.setVisibility(View.GONE);
//			_topBarTitle.setVisibility(View.VISIBLE);
//			_fornews.setVisibility(View.GONE);
//			_topBarTitle.setText(((ITDLApplication) getApplicationContext())
//					.getString(CommonDefn.TOP_BAR_TITLE));
//			if (cameFrom.indexOf(VOLUME) >= 0
//					|| cameFrom.indexOf(TURNOVER) >= 0)
//			{
////				_listViewColumn_4.setText(R.string.monitor_column_volume);
////				_listViewColumn_5.setText(R.string.monitor_column_turnover);
//				TDStockLog.d(TAG, "reset column name");
//			}
//			//----------modified by haibo, 2011-07-07, there're must have a path to more tab
////			_toolBtnTop20stock.setVisibility(View.VISIBLE);
//			_stockClassBtn.setVisibility(View.GONE);
//
//			//----------modified by haibo, 2011-07-07, there're must have a path to more tab
//
//			/* _toolBtnTop20stock.postInvalidate();
//				_stockClassBtn.postInvalidate();
//			_topBarTitle.postInvalidate();
//			_fornews.postInvalidate();
//			_listViewColumn_4.postInvalidate();
//			_listViewColumn_5.postInvalidate();*/
//
//		}
//		else if (MoreActivity.class.getSimpleName().equals(cameFrom))
//		{
//			_topBarTitle.setVisibility(View.VISIBLE);
//			_fornews.setVisibility(View.GONE);
//			_topBarTitle.setText(((ITDLApplication) getApplicationContext())
//					.getString(CommonDefn.TOP_BAR_TITLE));
//			/* _topBarTitle.postInvalidate();
//			 _fornews.postInvalidate();*/
//		}
//		else
//		{
//			_topBarTitle.setVisibility(View.GONE);
//			_topBarTitle.setText(R.string.monitor);
//			_fornews.setVisibility(View.VISIBLE);
//			/*_topBarTitle.postInvalidate();
//			_fornews.postInvalidate();*/
//		}
	}
	
	
	
	
	
	
	
	
	
	

	/*private void resetAdapter(final boolean isEditing)
	{
		final Runnable myUpdateResults = new Runnable()
		{
			public void run()
			{
				if (!isEditing)
				{
					_listView.setEnabled(false);
					_listView.setClickable(false);
					resetAdapterToAddAnotherClickableBtn();
					_listView.setClickable(true);
					_listView.setEnabled(true);
				}
				else
				{
					_listView.setEnabled(false);
					_listView.setClickable(false);
					_listView.setAdapter(_monitor_item_Adapter);
					_listView.setClickable(true);
					_listView.setEnabled(true);
				}
			}
		};

		new Thread()
		{
			public void run()
			{
				if (_messageHandler != null)
					_messageHandler.post(myUpdateResults);
			}
		}.start();
	}*/
	
	
	/*private boolean  isEditable() {
		 boolean result =  true;
		 String cameFrom = ((ITDLApplication) getApplicationContext())
			.getString(CommonDefn.ACTIVITY_CAME_FROM_KEY);
		  if(cameFrom == null) {
			  return true;
		  }
		  
		  final String[] from = { MoreActivity.class.getSimpleName(), 
				  		StockSectorActivity.class.getSimpleName(),
		  };
		  
		  for(String tmp : from) {
			  if(tmp.equals(cameFrom)) 
			  {
				  result = false;
				  return result;
			  }
		  }
		  
		  final String[] matchList = { CommonDefn.SECTOR_REG, CommonDefn.STOCK_LIST_TOP20_REG} ;
		  
		  for(String tmp : matchList) {
			  if(cameFrom.matches(tmp)) 
			  {
				  result = false;
				  return result;
			  }
		  }
		  
		 
		 return result;
		 
	}*/

	
	
	
	private void forwardToDestActivity(final int position)
	{
		if (position < 0 || _monitorList.size() < position + 1)
		{
			return;
		}
		//stock
		if (TextUtils.isDigitsOnly(_monitorList.get(position).itemCode
				.getText().toString()))
		{
			_prefsStockCode = getSharedPreferences(
					CommonDefn.SYSTEM_CURRENT_SETTING,
					Context.MODE_PRIVATE);
			_prefsStockCode.edit().putString(
					CommonDefn.PREFERENCE_STOCK_CODE,
					_monitorList.get(position).itemCode.getText()
							.toString()).commit();

			Intent intent = new Intent(getApplicationContext(),
					CurrentStockInfoActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
			
			SwitchTabHostActivity( 0, StockGroup.GetActivityGroupHostControl(),CurrentStockInfoActivity.class ,intent);
		/*	SwitchTabHostActivity(
			StockGroup.GetActivityGroupHostControl().ActivityForwardSwitch(this, CurrentStockInfoActivity.class, intent);*/
		}
		//ForeignExchange
		else if (ForeignExchangeInfo.ADAPTER.equals(_monitorList
				.get(position).adapter)
				&& ForeignExchangeInfo.CODE_TO_NAME
						.containsKey(_monitorList.get(position).itemCode
								.getText().toString()))
		{
			((ITDLApplication) getApplicationContext()).putString(
					CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ITEM,
					_monitorList.get(position).itemCode.getText()
							.toString());
			TDStockLog.d(TAG, "forwading item="
					+ _monitorList.get(position).itemCode.getText()
							.toString());

			if (ForeignExchangeGroup.group != null)
			{
				Intent intent = new Intent(getApplicationContext(),
						ForeignExchangeActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				
				//ForeignExchangeGroup.GetActivityGroupHostControl().ActivityForwardSwitch(this, ForeignExchangeActivity.class, intent);
				SwitchTabHostActivity( 3, ForeignExchangeGroup.GetActivityGroupHostControl(), ForeignExchangeActivity.class ,intent);
				
			}
			else
			{
				ForeignExchangeGroup.forceToGoToRelatingTab();
			}

		}

		else if (IntlMetalInfo.ADAPTER.equalsIgnoreCase(_monitorList
				.get(position).adapter))
		{
//			((ITDLApplication) getApplicationContext()).putString(
//					CommonDefn.ACTIVITY_CAME_FROM_KEY, this.getClass()
//							.getSimpleName());
			/*Intent intent =new Intent(getApplicationContext(),MetalActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(intent);*/

			if (MoreGroup.group != null)
			{
				Intent intent = new Intent(getApplicationContext(),
						MetalActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				
				
				//MoreGroup.GetActivityGroupHostControl().ActivityForwardSwitch(this, MetalActivity.class, intent);
				SwitchTabHostActivity( 4, MoreGroup.GetActivityGroupHostControl(), MetalActivity.class ,intent);
				
			}
			else
			{
				//MoreActivity._forwardingItemIndex = 4;
				MoreGroup.forceToGoToRelatingTab();
				//seems to hard to forward to  the metalActivity directly
			}
		}
		else if (OilInfo.ADAPTER
				.equalsIgnoreCase(_monitorList.get(position).adapter))
		{

			if (MoreGroup.group != null)
			{
				Intent intent = new Intent(getApplicationContext(),
						OilQuoteActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				
				//MoreGroup.GetActivityGroupHostControl().ActivityForwardSwitch(this, OilQuoteActivity.class, intent);
				SwitchTabHostActivity( 4, MoreGroup.GetActivityGroupHostControl(), OilQuoteActivity.class ,intent);
				
			}
			else
			{
				//MoreActivity._forwardingItemIndex = 5;
				MoreGroup.forceToGoToRelatingTab();
				
				//seems to hard to forward to  the metalActivity directly
			}

		}
		else if (_monitorList.get(position).isCop) {

			if (IndexGroup.group != null) {
				Intent intent = new Intent(getApplicationContext(),
						IndexCOPListActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
						| Intent.FLAG_ACTIVITY_NO_USER_ACTION);

				SwitchTabHostActivity(2,
						IndexGroup.GetActivityGroupHostControl(),
						IndexCOPListActivity.class, intent);
			} else {
				IndexGroup.forceToGoToRelatingTab();
			}

		} 
		else
		{

			((ITDLApplication) getApplicationContext()).putString(
					CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ITEM,
					_monitorList.get(position).itemCode.getText()
							.toString());
			TDStockLog.d(TAG, "forwading item="
					+ _monitorList.get(position).itemCode.getText()
							.toString());
			((ITDLApplication) getApplicationContext())
					.putString(
							CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ADAPTER,
							_monitorList.get(position).adapter);

			if (IndexGroup.group != null)
			{
				Intent intent = new Intent(getApplicationContext(),
						IndexActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);

				//IndexGroup.GetActivityGroupHostControl().ActivityForwardSwitch(this, IndexActivity.class, intent);
				SwitchTabHostActivity( 2, IndexGroup.GetActivityGroupHostControl(), IndexActivity.class ,intent);
			}
			else
			{
				IndexGroup.forceToGoToRelatingTab();
			}

		}

	}


	private class CallbackHandlerOnIndexFutures implements
		LightStreamerHandlerInterface
	{
		private NumberFormat	_formater;
		private String			_adapter;

		public CallbackHandlerOnIndexFutures()
		{
			_formater = DecimalFormat.getInstance();
			_formater.setMaximumFractionDigits(2);
			_formater.setMinimumFractionDigits(2);
			_adapter = IndexFuturesInfo.ADAPTER;  
		}

		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			//do nothing  for the monitor is editing.               
			if (_isInBackground || _isEditing || !isItemExist(itemName))
				return;

			if (!usingBlinkColumn)
			{
				ColorRefreshTask refresh = new ColorRefreshTask(
						PortfolioActivity.this,
						CommonDefn.HIGHLIGHT_BACKGROUND_COLOR, itemName);
				_messageHandler.postDelayed(refresh, 50);
			}

			final String[] fields = new String[4];
			if (itemName.matches("HSI:[0-9]"))
			{
				String mm = update.getNewValue(IndexFuturesInfo.MM);
				fields[0] = String.format("恆指%s月", mm != null ? Integer.parseInt(mm) : CommonDefn.DEFAULT_FIELD_VALUE);
				if(((ITDLApplication)getApplicationContext()).getModeType() == CommonDefn.ModeType.ACCOUNTLOGIN && !((ITDLApplication)getApplicationContext()).getIsRealtimeFutures())
				{
					fields[0] = fields[0] + "*";
				}
				fields[1] = StringUtils.roundDownInteger(update.getNewValue(IndexFuturesInfo.LAST));
//				fields[2] = StringUtils.formatNumberByNetWorldIndex(update.getNewValue(IndexFuturesInfo.NET));
				fields[2] = StringUtils.formatToFiveCharsRule(update.getNewValue(IndexFuturesInfo.NET));
				fields[3] = update.getNewValue(IndexFuturesInfo.NETPRECENTAGE);
//				fields[3] = fields[3]!=null?StringUtils.formatNumberByNetPerectage(fields[3], 4):CommonDefn.DEFAULT_FIELD_VALUE;
				fields[3] = fields[3]!=null?(StringUtils.formatToFiveCharsRule(fields[3]) + "%"):CommonDefn.DEFAULT_FIELD_VALUE;
				_adapter =/* IndexFuturesInfo.ADAPTER;*/ _indexFuturesAdapter;
			}
			else if (itemName.matches("HHI:[0-9]"))
			{
				String mm = update.getNewValue(IndexFuturesInfo.MM);
				fields[0] = String.format("國企%s月", mm != null ? Integer.parseInt(mm) : CommonDefn.DEFAULT_FIELD_VALUE);
				if(((ITDLApplication)getApplicationContext()).getModeType() == CommonDefn.ModeType.ACCOUNTLOGIN && !((ITDLApplication)getApplicationContext()).getIsRealtimeFutures())
				{
					fields[0] = fields[0] + "*";
				}
				fields[1] = StringUtils.roundDownInteger(update.getNewValue(IndexFuturesInfo.LAST));
//				fields[2] = StringUtils.formatNumberByNetWorldIndex(update.getNewValue(IndexFuturesInfo.NET));
				fields[2] = StringUtils.formatToFiveCharsRule(update.getNewValue(IndexFuturesInfo.NET));
				fields[3] = update.getNewValue(IndexFuturesInfo.NETPRECENTAGE);
//				fields[3] = fields[3]!=null?StringUtils.formatNumberByNetPerectage(fields[3], 4):CommonDefn.DEFAULT_FIELD_VALUE;
				fields[3] = fields[3]!=null?(StringUtils.formatToFiveCharsRule(fields[3]) + "%"):CommonDefn.DEFAULT_FIELD_VALUE;
				_adapter =/* IndexFuturesInfo.ADAPTER;*/  _indexFuturesAdapter;;
			}
			else if (itemName.matches("SSI:[0-9]"))
			{
				String mm = update.getNewValue(WorldFuturesInfo.MM);
				fields[0] = String.format("日經%s月", mm != null ? Integer.parseInt(mm) : CommonDefn.DEFAULT_FIELD_VALUE);
				fields[1] = StringUtils.roundDownInteger(update.getNewValue(WorldFuturesInfo.LAST));
//				fields[2] = StringUtils.formatNumberByNetWorldIndex(update.getNewValue(WorldFuturesInfo.NET));
				fields[2] = StringUtils.formatToFiveCharsRule(update.getNewValue(WorldFuturesInfo.NET));
				fields[3] = CommonDefn.DEFAULT_FIELD_VALUE;
				_adapter = WorldFuturesInfo.ADAPTER;
			}
			else if (itemName.matches("DJI:[0-9]"))
			{
				String mm = update.getNewValue(WorldFuturesInfo.MM);
				fields[0] = String.format("道指%s月", mm != null ? Integer.parseInt(mm) : CommonDefn.DEFAULT_FIELD_VALUE);
				fields[1] = StringUtils.roundDownInteger(update.getNewValue(WorldFuturesInfo.LAST));
//				fields[2] = StringUtils.formatNumberByNetWorldIndex(update.getNewValue(WorldFuturesInfo.NET));
				fields[2] = StringUtils.formatToFiveCharsRule(update.getNewValue(WorldFuturesInfo.NET));
				fields[3] = CommonDefn.DEFAULT_FIELD_VALUE;
				_adapter = WorldFuturesInfo.ADAPTER;
			}

			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					//updateRowInTable(itemName, fields);
						TDStockLog.d(TAG, String.format("itemName=%s, fields=%s, adapter=%s", itemName, fields[0] + "," + fields[1]  + ","  + fields[2] + "," + fields[3], _adapter));
						updateAdapter(itemName, fields, _adapter);
					
//					if (usingBlinkColumn)
//					{
//						Message exMessage;
//						int     index;
//
//						index = FindListItem(itemName);
//						if (index == -1)
//							return;
//						
//						exMessage = /*new Message();*/ UIUpdater.obtainMessage();
//						exMessage.what = INFO_CONTENT_UPDATE;
//						exMessage.obj = itemName;
//						exMessage.arg1 = index;
//						UIUpdater.sendMessage(exMessage);
//					}					
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}
	}

	private class CallbackHandlerOnCOP implements LightStreamerHandlerInterface
	{
		private NumberFormat	_formater;
		private String			_adapter;
	
		public CallbackHandlerOnCOP()
		{
			_formater = DecimalFormat.getInstance();
			_formater.setMaximumFractionDigits(2);
			_formater.setMinimumFractionDigits(2);
			_adapter = IndexFuturesInfo.ADAPTER + IndexFuturesInfo.COP;  /*IndexFuturesInfo.adapter_realtime;*/
		}
	
		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			//do nothing  for the monitor is editing.               
			if (_isInBackground || _isEditing || !isItemExist(itemName))
				return;
	
			if (!usingBlinkColumn)
			{
				ColorRefreshTask refresh = new ColorRefreshTask(
						PortfolioActivity.this,
						CommonDefn.HIGHLIGHT_BACKGROUND_COLOR, itemName);
				_messageHandler.postDelayed(refresh, 50);
			}
	
			final String[] fields = new String[4];
			
			String mm = update.getNewValue(IndexFuturesInfo.MM);
			if (itemName.matches("HSI:[0-9]"))
			{
				fields[0] = String.format("恆%s月C", mm != null ? Integer.parseInt(mm) : CommonDefn.DEFAULT_FIELD_VALUE);
			}
			else if (itemName.matches("HHI:[0-9]"))
			{
				fields[0] = String.format("國%s月C", mm != null ? Integer.parseInt(mm) : CommonDefn.DEFAULT_FIELD_VALUE);
			}
			fields[1] = StringUtils.roundDownInteger(update.getNewValue(IndexFuturesInfo.COP));
			fields[2] = CommonDefn.DEFAULT_FIELD_VALUE;
			fields[3] = CommonDefn.DEFAULT_FIELD_VALUE;
	
			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					updateAdapter(itemName, fields, _adapter);
	//				if (usingBlinkColumn)
	//				{
	//					Message exMessage;
	//					int     index;
	//
	//					index = FindListItem(itemName);
	//					if (index == -1)
	//						return;
	//					
	//					exMessage = /*new Message();*/ UIUpdater.obtainMessage();
	//					exMessage.what = INFO_CONTENT_UPDATE;
	//					exMessage.obj = itemName;
	//					exMessage.arg1 = index;
	//					UIUpdater.sendMessage(exMessage);
	//				}					
				}
			};
	
			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}
	}
	
	private class LightStreamerHandlerOnIndex implements
		LightStreamerHandlerInterface
	{
		private String[]		_itemName;
		private NumberFormat	_formater;
		private String			_adapter;
		private boolean 		_isSSEI;
		public LightStreamerHandlerOnIndex(String[] itemName, String adapter, String... isSSEI)
		{
			if(isSSEI.length > 0) _isSSEI = true;
			else _isSSEI = false;
			_itemName = itemName;
			_formater = DecimalFormat.getInstance();
			_formater.setMaximumFractionDigits(2);
			_formater.setMinimumFractionDigits(2);
			_adapter = adapter;
		}

		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			//do nothing  for the monitor is editing.
			if (_isEditing || _isInBackground || !isItemExist(itemName))
				return;
			/*
			               if(_isInBackground)
			               {
			                    return;
			               }
			*/

			if (!usingBlinkColumn)
			{
				//if(update.isValueChanged( StockInfo.Nominal))
				//{
				ColorRefreshTask refresh = new ColorRefreshTask(
						PortfolioActivity.this,
						CommonDefn.HIGHLIGHT_BACKGROUND_COLOR, itemName);
				_messageHandler.postDelayed(refresh, 50);
				//}
			}

			final String[] fields = new String[4];

			fields[0] = _itemName[itemPos - 1];
			if(_isSSEI && ((ITDLApplication)getApplicationContext()).getModeType() == CommonDefn.ModeType.ACCOUNTLOGIN && !((ITDLApplication)getApplicationContext()).getIsRealtimeSSEI())
			{
				fields[0] = fields[0] + "*";
			}
			/*if(fields[0].endsWith("(延遲)"))
			{
				fields[0] = fields[0].substring(0, fields[0].length()-4);
			}
			else */if(StringUtils.EN_CHARS.contains(fields[0].substring(fields[0].length()-1, fields[0].length())))
			{
				fields[0] = fields[0].substring(0, 5);
			}
			if (_adapter.equals(IndexInfo.ADAPTER))
			{
				fields[1] = StringUtils.roundDownInteger(update.getNewValue(IndexInfo.INDEXLAST));
//				fields[2] = StringUtils.formatNumberByNetIndex(update.getNewValue(IndexInfo.INDEXNET));
				fields[2] = StringUtils.formatToFiveCharsRule(update.getNewValue(IndexInfo.INDEXNET));
//				fields[3] = StringUtils.formatNumberByNetPerectage(update.getNewValue(IndexInfo.INDEXNETPRECENTAGE), 4);
				fields[3] = StringUtils.formatToFiveCharsRule(update.getNewValue(IndexInfo.INDEXNETPRECENTAGE)) + "%";
			}
			else if (_adapter.equals(WorldIndexInfo.ADAPTER))
			{
				fields[1] = StringUtils.roundDownInteger(update.getNewValue(WorldIndexInfo.LAST));
//				fields[2] = StringUtils.formatNumberByNetWorldIndex(update.getNewValue(WorldIndexInfo.NET));
				fields[2] = StringUtils.formatToFiveCharsRule(update.getNewValue(WorldIndexInfo.NET));
				fields[3] = StringUtils.formatToFiveCharsRule(update.getNewValue(WorldIndexInfo.NETPERCENTAGE)) + "%";
			}
			else if (_adapter.equals(WorldIndexDelayInfo.ADAPTER))
			{
				fields[1] = StringUtils.roundDownInteger(update.getNewValue(WorldIndexDelayInfo.LAST));
//				fields[2] = StringUtils.formatNumberByNetWorldIndex(update.getNewValue(WorldIndexDelayInfo.NET));
				fields[2] = StringUtils.formatToFiveCharsRule(update.getNewValue(WorldIndexDelayInfo.NET));
				fields[3] = StringUtils.formatToFiveCharsRule(update.getNewValue(WorldIndexDelayInfo.NETPERCENTAGE)) + "%";
			}

			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					//updateRowInTable(itemName, fields);
					updateAdapter(itemName, fields, _adapter);
//					if (usingBlinkColumn)
//					{
//						Message exMessage;
//						int     index;
//						
//						index = FindListItem(itemName);
//						if (index == -1)
//							return;
//						
//						exMessage = /*new Message();*/ UIUpdater.obtainMessage();
//						exMessage.what = INFO_CONTENT_UPDATE;
//						exMessage.obj = itemName;
//						exMessage.arg1 = index;
//						UIUpdater.sendMessage(exMessage);
//					}				
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}
	}

	private class LightStreamerHandlerOnFX implements
		LightStreamerHandlerInterface
	{
		private NumberFormat	_formater;

		public LightStreamerHandlerOnFX()
		{
			_formater = DecimalFormat.getInstance();
			_formater.setMaximumFractionDigits(4);
			_formater.setMinimumFractionDigits(4);
			_formater.setGroupingUsed(false);
		}

		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			//do nothing  for the monitor is editing.               
			if (_isInBackground || _isEditing || !isItemExist(itemName))
				return;
			/*
			               if(_isInBackground)
			               {
			                    return;
			               }
			*/

			if (!usingBlinkColumn)
			{
				//if(update.isValueChanged( StockInfo.Nominal))
				//{
				ColorRefreshTask refresh = new ColorRefreshTask(
						PortfolioActivity.this,
						CommonDefn.HIGHLIGHT_BACKGROUND_COLOR, itemName);
				_messageHandler.postDelayed(refresh, 50);
				//}
			}

			final String[] fields = new String[4];
			fields[0] = ForeignExchangeInfo.CODE_TO_NAME.get(itemName);
			
			try
			{
				Double bid = Double.parseDouble(update.getNewValue(ForeignExchangeInfo.FXBID));
				Double ask = Double.parseDouble(update.getNewValue(ForeignExchangeInfo.FXASK));

				fields[1] = /*update.getNewValue(ForeignExchangeInfo.FXPREV);*/_formater.format( (bid  + ask ) /2);
				while(fields[1].endsWith("0")) {
					fields[1] = fields[1].substring(0, fields[1].length()-1);
				}
				
				if(fields[1].length() >6) {
					fields[1] = fields[1].substring(0, 6);
				}
				
				
			}
			catch (NumberFormatException e)
			{
				
				fields[1]  = CommonDefn.DEFAULT_FIELD_VALUE2;
			}
				
			fields[2] = update.getNewValue(ForeignExchangeInfo.FXNET);

			fields[3] = update.getNewValue(ForeignExchangeInfo.FXNET_PERCENTAGE);
			
			fields[3] = StringUtils.formatNumberByNetPerectage(fields[3], 4);
			/*String net_percentage = "0";
			try
			{
				if (Math.abs(Double.parseDouble(fields[3])) > CommonDefn.APPROACH_ZERO)
				{
					net_percentage = _formater.format(Double
							.parseDouble(fields[3]) *//** 100.00d*//*
					)
							+ "%";
					fields[3] = net_percentage;
				}
			}
			catch (NumberFormatException e)
			{
				//e.printStackTrace();
			}*/

			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					//updateRowInTable(itemName, fields);
					updateAdapter(itemName, fields,
							ForeignExchangeInfo.ADAPTER);
//					if (usingBlinkColumn)
//					{
//						Message exMessage;
//						int     index;
//						
//						index = FindListItem(itemName);
//						if(index == -1)
//							return;
//						exMessage = /*new Message();*/ UIUpdater.obtainMessage();
//						exMessage.what = INFO_CONTENT_UPDATE;
//						exMessage.obj = itemName;
//						exMessage.arg1 = index;
//						UIUpdater.sendMessage(exMessage);
//					}					
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}
	}

	private class LightStreamerHandlerOnOil implements
		LightStreamerHandlerInterface
	{
		public void onUpdate(final int itemPos, final String itemName,
				final UpdateInfo update)
		{
			//do nothing  for the monitor is editing.               
			if (_isInBackground || _isEditing || !isItemExist(itemName))
				return;
			/* 
			               if(_isInBackground)
			               {
			                    return;
			               }
			*/

			if (!usingBlinkColumn)
			{
				//if(update.isValueChanged( StockInfo.Nominal))
				//{
				ColorRefreshTask refresh = new ColorRefreshTask(
						PortfolioActivity.this,
						CommonDefn.HIGHLIGHT_BACKGROUND_COLOR, itemName);
				_messageHandler.postDelayed(refresh, 50);
				//}
			}

			final String[] fields = new String[4];
			fields[0] = OilInfo.SUBSCRIBE_ITEMS_NAME_4_MONITOR[0];

			fields[1] = update.getNewValue(OilInfo.LAST);
			fields[2] = update.getNewValue(OilInfo.NET);

			try
			{
				double net = Double.parseDouble(fields[2]);
				double now = Double.parseDouble(fields[1]);
				double netPercentage = ((now) / (now - net) - 1) * 100.00d;
				fields[3] = StringUtils.FormatNumber(
						StringUtils.ITDLNumber.NETPERCENTAGE, String
								.valueOf(netPercentage));
			}
			catch (Exception e)
			{
			}

			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					//updateRowInTable(itemName, fields);
					updateAdapter(itemName, fields, OilInfo.ADAPTER);
//					if (usingBlinkColumn)
//					{
//						Message exMessage;
//						int     index;
//						
//						index = FindListItem(itemName);
//						if (index == -1)
//							return;
//						exMessage = /*new Message();*/ UIUpdater.obtainMessage();
//						exMessage.what = INFO_CONTENT_UPDATE;
//						exMessage.obj = itemName;
//						exMessage.arg1 = index;
//						UIUpdater.sendMessage(exMessage);
//					}					
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
						_messageHandler.post(myUpdateResults);
				}
			}.start();
		}
	}

	private boolean isItemExist(final String itemName)
	{
		boolean result = true;
		for (MonitorViewHolder holder : _dropList)
		{
			if (holder.itemCode != null
					&& itemName.equals(holder.itemCode.getText()
							.toString()))
			{
				result = false;
				break;
			}
		}
		return result;
	}

//	private class ForwardToUserDiary extends DefaultClickHandler
//	{
//		private int	_position;
//
//		ForwardToUserDiary(Context context, int position)
//		{
//			super(context);
//			_position = position;
//		}
//
//		@Override
//		protected void onDefaultAction()
//		{
//			((ITDLApplication) getApplicationContext()).putString(
//					CommonDefn.STOCK_DIARY_EDITING_ITEMCODE, _monitorList
//							.get(_position).itemCode.getText()
//							.toString());
//			((ITDLApplication) getApplicationContext()).putString(
//					CommonDefn.STOCK_DIARY_EDITING_ITEMNAME, _monitorList
//							.get(_position).itemName.getText()
//							.toString());
//			((ITDLApplication) getApplicationContext()).putString(
//					CommonDefn.STOCK_DIARY_EDITING_CURRENT_PRICE,
//					_monitorList.get(_position).itemValue.getText()
//							.toString());
//
//			/*Intent intent =new Intent(getApplicationContext(),StockDiaryActivity.class);
//			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//			startActivity(intent);*/
//
//			Intent intent = new Intent(getApplicationContext(),
//					StockDiaryActivity.class);
//			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
//			/*View viewIntent = MonitorGroup.group.getLocalActivityManager()
//					.startActivity(
//							StockDiaryActivity.class.getSimpleName(),
//							intent).getDecorView();
//			MonitorGroup.group.setContentView(viewIntent); // modify by ouyangzhihui 2011-05-16
//*/		
//			
//			
//			SwitchForwardActivity(StockDiaryActivity.class, intent);
//		
//		
//		}
//
//	}

	@Override
	protected void onPause()
	{
		lastTag = cameFromTag;
		this._isEditing = false;
		TDStockLog.d(TAG, "On Pause executed!");		
		super.onPause();
		
		if (_toast != null)
			_toast.cancel();
		//離開當前頁面，關閉太陽花
		clearSunFlower(); //by ouyangzhihui 2011-08-11
		LightStreamerUnsubscribeAll();
		((ITDLApplication) getApplicationContext()).putString(CommonDefn.ACTIVITY_CAME_FROM_KEY, "");
		
		if (System.currentTimeMillis() - lastRunntimeInOnPause < 500l
				&& lastRunntimeInOnPause != 1l)
		{
			TDStockLog.d(TAG, "don't execute twice during a short term in onPause!");
			return;
		} //don't execute twice during a short term
		lastRunntimeInOnPause = System.currentTimeMillis();
		
		
		/*if(_myClient != null) {
			_myClient.closeConnection();
		}*/
		
//		unRegisterAppExitReceiver();

	/*	if (_streamerTimeoutHandler != null)
		{
			_streamerTimeoutHandler.resetCounter();
		}
*/
		/*if (_cdrHelper != null)
		{
			_cdrHelper._isPause = true;
			_cdrHelper.saveCdrCounter(false);
		}*/

//		_comeFrom = null;

	/*	{

			if (_subscrRefs == null || _subscrRefs.isEmpty())
			{
				return;
			}

			unSubscribeAllItems();
			

		}
*/
	}
	
	
	

	private void resetTitle()
	{
		_listViewTitle
				.setVisibility(((ITDLApplication) getApplicationContext())
						.getDataMode() == CommonDefn.DataMode.Delay ? View.VISIBLE
						: View.GONE);
	}

	protected Context getMyOwnContext()
	{
		//return this;
		return getParent();
	}

	private static void sortAsNumbersByAsc(String[] source)
	{
		int length = source.length;
		for (int index = 0; index < length; index++)
		{
			for (int item = index + 1; item < length; item++)
			{
				if (Integer.parseInt(source[index], 10) > Integer.parseInt(
						source[item], 10))
				{
					String tmp = source[index];
					source[index] = source[item];
					source[item] = tmp;
				}
			}

		}
	}
	protected SunFlowerView				sunFlowerView2;
	/*
	 * start SunFlower animation
	 */
	private void startSunFlower(final Context atContext)
	{
		
		Activity  activity = PortfolioActivity.this;
		if(atContext instanceof Activity)
		{
			activity = (Activity)atContext;
		}
		
		
		activity.runOnUiThread(new Runnable()
		{
			public void run()
			{ 
				
				try
				{
					// init SunFlower Animation.
					if (mWindowManager == null)
					{
						mWindowManager = (WindowManager)atContext.getSystemService(Context.WINDOW_SERVICE);
					}

					if (sunFlowerView2 == null)
					{
						sunFlowerView2 = new SunFlowerView(atContext);
						sunFlowerView2.startAnimation();
						sunFlowerView2.setVisibility(View.VISIBLE);
					}
					else
					{
						if (sunFlowerView2.getParent() != null)
							mWindowManager.removeView(sunFlowerView2);
					}
					
					// Keep having BadToken exception once in a while, but not hanging the application
					mWindowManager.addView(sunFlowerView2, getParams());							
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
		
		
		
		
	
	}
	/*
	 * clear SunFlower animation.
	 */
	private void clearSunFlower()
	{
		TDStockLog.d(TAG, "ready to clear the sunflower");
		Runnable  stopJob = new Runnable()
		{
			 public void run() 
			 {
					try
					{
						if (mWindowManager == null)
							mWindowManager = (WindowManager) PortfolioActivity.this.getMyOwnContext().getSystemService(Context.WINDOW_SERVICE);

						if (mWindowManager != null && sunFlowerView2 != null  && sunFlowerView2.isRunning())
						{
							sunFlowerView2.setVisibility(View.GONE);
							sunFlowerView2.stopAnimation();
							mWindowManager.removeView(sunFlowerView2);							
							sunFlowerView2 = null;							
							TDStockLog.d(TAG, "clear the sunflower successfully!");
						}
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
					finally
					{
						sunFlowerView2 = null;
					}
			 }
		 };
		 
		 if(_messageHandler != null) {
			 _messageHandler.post(stopJob);
		 }
	
		
		
		
		
		
	}
	


	//reset all variable that linked to the page
//	public void resetPage()
//	{
//		((ITDLApplication) getApplicationContext()).putString(
//				CommonDefn.ACTIVITY_CAME_FROM_KEY, _comeFrom);
//	}

	private void startCdrCounter()
	{
	/*	if (_streamerTimeoutHandler != null)
		{
//			_streamerTimeoutHandler.startCounter(_cdrHelper != null ? _cdrHelper._cdrCounter : 0);
		}*/
	}


//	private class CallbackHandlerOnSyncTradingTime implements
//		LightStreamerHandlerInterface
//	{
//		final String	TRUE	= "true";
//		private boolean _isPostedDataWhenIsNotTradingTime =  false;
//
//		public void onUpdate(int itemPos, String itemName,
//				final UpdateInfo update)
//		{
//			try
//			{
//				_isTradingTime = TRUE.equalsIgnoreCase(update
//						.getNewValue(HolidayInfo.FIELD_1));
//				
////				_cdrHelper._isPause = _isTradingTime ? false : true; //set pause if is not trading time
//				TDStockLog.d(TAG, "is trading time:"
//						+ update.getNewValue(HolidayInfo.FIELD_1)); //modified by haibo, 2011-06-30
//				
//				
//			/*	if(_isTradingTime ) {
//					_isPostedDataWhenIsNotTradingTime = false;
//				}
//				else {
//					if(!_isPostedDataWhenIsNotTradingTime ) {
//						sendCdrInfo();    //send cdr info if got the leave time
//					}
//					_isPostedDataWhenIsNotTradingTime = true;
//				}*/
//				
//				
//				
//			}
//			catch (Exception e)
//			{
//				e.printStackTrace();
//			}
//		}
//	}

	public void sendCdrInfo()
	{
	/*	if (_cdrHelper != null)
		{
			
			if(!_isTradingTime  || ((ITDLApplication) getApplicationContext()).getDataMode() == CommonDefn.DataMode.Delay ) 
			{
				return;   //don't send the cdr info if it  is free
			}

			try
			{
				String userId = this.getUser();
				String account = getSessionAccount();
				account = account.substring(0, account.length() - 2);
				String deviceId = this.getDeviceId();
				String dvcTime = CdrHelper.DVC_TIME;DateUtils
						.formatDate(new Date(),
								CdrHelper.YEAR_MONTH_DAT_TIME_FORMAT);
				String dvcType = String.valueOf(CommonDefn.DEVICE_TYPE);
				String sessionEndTime = DateUtils.formatDate(new Date(),
						CdrHelper.YEAR_MONTH_DAT_TIME_FORMAT);
				String sessionStartTime = DateUtils.formatDate(
						_cdrHelper._startTime,
						CdrHelper.YEAR_MONTH_DAT_TIME_FORMAT);
				String svcInfo = CommonDefn.TDSTOCK_VERSION getAppVersion() + "/"
						+ android.os.Build.VERSION.RELEASE;
				String svcSubType = CdrHelper.SVC_SUB_TYPE;
				String svcTime = String
						.valueOf(_isTradingTime ? _cdrHelper._cdrCounter
								: 0);   

				String svcCount = CdrHelper.SVC_COUNT;
				String seqNo = String.valueOf(_cdrHelper.getNextSeqNo());
				String svcType = CdrHelper.SVC_TYPE;
				String lsTime = DateUtils.formatDate(_cdrHelper._startTime,
						CdrHelper.YEAR_MONTH_DAT_TIME_FORMAT);
					_cdrHelper._lsTime;

				TDStockLog
						.e(
								TAG,
								String
										.format(
												"%s, %s,%s, %s,%s, %s,%s, %s,%s, %s,%s, %s,%s, %s,",
												userId, account,
												deviceId, dvcTime,
												dvcType,
												sessionEndTime,
												sessionStartTime,
												svcInfo,
												svcSubType,
												svcTime, svcCount,
												seqNo, svcType,
												lsTime));
				_cdrHelper._isStopFlag = true;
				boolean postResult = _cdrHelper.postCdrCounterToServer(
						userId, account, deviceId, dvcTime, dvcType,
						sessionEndTime, sessionStartTime, svcInfo,
						svcSubType, svcTime, svcCount, seqNo, svcType,
						lsTime);
				_cdrHelper.saveCdrCounter(true);
				TDStockLog.e(TAG, "post cdr msg to server, and the result is "
						+ (postResult ? "true" : "false"));
			}
			catch (Exception e)
			{
				e.printStackTrace();
			}

		}*/
	}

	public void onCdrPause()
	{
		/*if (_cdrHelper != null)
		{
			_cdrHelper._isPause = true;
		}*/
	}

	public void onCdrResume()
	{
		/*if (_cdrHelper != null)
		{
			_cdrHelper._isPause = false;
		}*/

	}

	public void onCdrCounterComeTo15Minutes()
	{
		sendCdrInfo();
	}

	public synchronized void exitApp()
	{
		//sendCdrInfo();
		super.exitApp();

	}

	public static void showToast(Activity paramActivity, int paramInt)
	{
		if (_toast == null)
			_toast = new Toast(paramActivity);
		
		View localView = paramActivity.getLayoutInflater().inflate(
				R.layout.richtoast_for_monitor_edit_tips, null);
		/*ImageView localImageView = (ImageView) localView
				.findViewById(R.id.dialog_id);
		if (paramInt == 0)
			localImageView.setImageResource(R.drawable.dialog_default_icon);
		else if (paramInt == 1)
			localImageView.setImageResource(R.drawable.dialog_alert_icon);
		else
			localImageView.setImageResource(R.drawable.dialog_err_icon);*/
		_toast.setView(localView);
		_toast.setDuration(Toast.LENGTH_LONG);
		_toast.show();
	}
	
	@Override
	protected void onNewIntent(Intent intent)
	{
		super.onNewIntent(intent);
		updateListViewUnderUnEditMode();
		TDStockLog.d(TAG, "onNewIntent executed !");
		//this.onPause();
		
		if(appHost.LSClient_IsConnected())
			LightStreamerUnsubscribeAll();
	}
	
	
	@Override
	protected void onStop()
	{
		if(_listView != null)
			_listView.setVisibility(View.GONE);
		
		updateListViewUnderUnEditMode();
		
		if (mWindowManager != null)
		{
			if(sunFlowerView2 != null)
			{
				mWindowManager.removeView(sunFlowerView2);
				sunFlowerView2 = null;
			}
			mWindowManager = null;
		}
		super.onStop();		
	}
	
	
	private  void updateListViewUnderUnEditMode() {
		this._isEditing = false;
		for (MonitorViewHolder holder : _monitorList)
		{
			holder.isEditable = _isEditing;
		}
		if(_listView.getVisibility() == View.VISIBLE)
			_monitor_item_Adapter.notifyDataSetChanged();
		
	}


	@Override
	public ActivityGroupController GetActivityGroupController()
	{  
		//share the same tab with  more group,
		return MonitorGroup.GetActivityGroupHostControl() == null ?  MoreGroup.GetActivityGroupHostControl() : MonitorGroup.GetActivityGroupHostControl() ;
	}
	

	@Override
	public void onUpdate(String iIdentifier, int iSchemaIndex,
			String iSchemaValue, UpdateInfo iUpdateInfo)
	{
//		TDStockLog.d(TAG, "cameFromTag-DUG="+iIdentifier+","+iSchemaIndex+","+iSchemaValue+","+iUpdateInfo.getItemName());
		super.onUpdate(iIdentifier, iSchemaIndex, iSchemaValue, iUpdateInfo);
		if(IDENTIFIER_0.equals(iIdentifier) )
		{
			_callbackHandler00.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_1.equals(iIdentifier) )
		{
			_callbackHandler01.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_2.equals(iIdentifier) )
		{
			_callbackHandler02.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_3.equals(iIdentifier) /*|| IDENTIFIER_3_0.equals(iIdentifier)*/)
		{
			_callbackHandler03.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_4_0.equals(iIdentifier) )
		{
			_callbackHandler04_0.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_4_1.equals(iIdentifier) )
		{
			_callbackHandler04_1.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_4_2.equals(iIdentifier) )
		{
			_callbackHandler04_2.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_4_3.equals(iIdentifier) )
		{
			_callbackHandler04_3.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_5.equals(iIdentifier) )
		{
			_callbackHandler05.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
		else if(IDENTIFIER_6.equals(iIdentifier) )
		{
			_callbackHandler06.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}
	/*	else if(IDENTIFIER_7.equals(iIdentifier) )
		{
			_callbackHandler07.onUpdate(iSchemaIndex, iSchemaValue, iUpdateInfo);
		}*/
		
		
		// 當數據Update完之後關閉太陽花
		if(sunFlowerView2 != null  &&   (sunFlowerView2.isShown() ))
			clearSunFlower(); //by haibo, 2011-11-03
		
	}

	@Override
	protected H_CODE GetDataFromHttpServer()
	{
		return HttpAppInfo.SendStockSectorRequest(actContext, cameFromTag.replace("sector=", ""), this,"mode");
	}

	private H_CODE GetMonitorItemDataFromServer()
	{
		//startSunFlower(getMyOwnContext());   
		return HttpAppInfo.GetBookMark(actContext, this, "item");
	}

	@Override
	protected void H_UserClient_HttpRequest_Response_Sub(
			final H_UserClient_HttpRequest_Result iResult)
	{
		if (!"0".equals(iResult.MStatus))
		{
			ShowMessageDialog(iResult.MError + "(" + iResult.MStatus + ")");
			return;
		}

		if (iResult.contentStores.size() <= 0)
			return;
		if ("item".equals(iResult.seqID))
		{
			List<String[]> items = iResult.contentStores;

			if (items == null)
			{
				return;
			}

			TDStockLog.d(TAG, TAG + "----->items size-------->"
					+ (items == null ? 0 : items.size()));
			_messageHandler.post(new LoadingServerData(items));
		}
		else if ("mode".equals(iResult.seqID))
		{

			final Runnable job = new Runnable()
			{
				public void run()
				{
					try
					{
						int count = iResult.contentStores.size();
						String[] _stockCodes = new String[count];
						for (int index = 0; index < count; index++)
						{
							_stockCodes[index] = iResult.contentStores
									.get(index)[0];
						}
						sortAsNumbersByAsc(_stockCodes);

						_monitorList.clear();
						for (final String stk : _stockCodes)
						{
							MonitorViewHolder monitorViewHolder = new MonitorViewHolder();
							monitorViewHolder.isEditable = _isEditing;
							monitorViewHolder.adapter = StockInfo.ADAPTER;
							monitorViewHolder.isTop20orSector = true;
							monitorViewHolder.itemCode = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemCode.setText(stk);
							monitorViewHolder.itemName = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemValue = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemNet = new TextView(
									PortfolioActivity.this);
							monitorViewHolder.itemNetPercentage = new TextView(
								    PortfolioActivity.this);
							_monitorList.add(monitorViewHolder);
						}
						_monitor_item_Adapter.notifyDataSetChanged();

						if (_callbackHandler00 == null)
							_callbackHandler00 = new CallbackHandlerOnStock();
						{
							LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
									StockInfo.ADAPTER);
							interestItem.SetSubscribeItem(_stockCodes);
							interestItem
									.SetSubscribeSchema(StockInfo.MONITOR_FIELDS);

							LightStreamerSubscribeItem(IDENTIFIER_0,
									interestItem,
									PortfolioActivity.this);
						}
					}
					catch (Exception e)
					{
						handleLightStreamerException(e, this);
					}
				}
			};

			new Thread()
			{
				public void run()
				{
					_messageHandler.post(job);
				}
			}.start();
		}

	}

	
	
	
	private class LoadingServerData implements Runnable
	{
		private List<String[]>	items;

		public LoadingServerData(List<String[]> items)
		{
			this.items = items;
		}

		@Override
		public void run()
		{
			//to avoid run the code in same time(little interval);
			
			if(runTimeOnLightStreamer != 1L && (System.currentTimeMillis()   - runTimeOnLightStreamer < LEAST_INTERVAL_OF_MS)) 
			{
				return;
			}
			
			runTimeOnLightStreamer = System.currentTimeMillis();
			//to avoid run the code in same time(little interval);
			
			TDStockLog.d(TAG, "ready to  load  date from server");
			if (items == null || items.size() <= 0)
			{
				//clearSunFlower();
				return;
			}
			if (items != null && items.size() == 0)
			{
				//clearSunFlower();
				//啟動太陽花
				startSunFlower(getMyOwnContext());
				return;
			}

			_isCustomerSubscribedItems = true;
			_monitorList.clear();

			List<String> iIdList = new ArrayList<String>();
			List<LS_SubscriptionItem> iItemList = new ArrayList<LS_SubscriptionItem>();
			List<ILS_UserClient_Response> iResponseList = new ArrayList<ILS_UserClient_Response>();

			StringBuffer foreignExchangeInfoItems = null; // 外汇

			StringBuffer indexFuturesInfoRealtimeItems = null; // 实时指数期货
			StringBuffer indexFuturesInfoRealtimeNames = null;

			StringBuffer indexFuturesInfoDelayItems = null;// 延迟指数期货
			StringBuffer indexFuturesInfoDelayNames = null;

			StringBuffer indexInfoItems = null;// 指数
			StringBuffer indexInfoNames = null;

			StringBuffer intlMetalInfoItems = null; // 国际金属
			StringBuffer intlMetalInfoNames = null;

			StringBuffer oilInfoItems = null;// 油价
			StringBuffer oilInfoNames = null;

			StringBuffer stockInfoItems = null; // 股票

			StringBuffer copItems = null; // COP

			StringBuffer worldIndexDelayInfoItems = null; // 延迟 国际指数
			StringBuffer worldIndexDelayInfoNames = null;

			StringBuffer worldIndexInfoItems = null;// 国际指数
			StringBuffer worldIndexInfoNames = null;

			StringBuffer worldFuturesInfoItems = null;// 国际期货
			boolean isSubscribedOil = false;
			_listView.SetEditingMode(_isEditing);
			BookMarkUtil bm = BookMarkUtil
					.getInstance(PortfolioActivity.this);

			for (final String[] array : items)
			{
				MonitorViewHolder monitorViewHolder = new MonitorViewHolder();
				monitorViewHolder.isEditable = _isEditing;
				monitorViewHolder.isTop20orSector = false;
				monitorViewHolder.isCop = COP_TAG.equalsIgnoreCase(array[1]);
				// monitorViewHolder.adapter =
				// BookMarkUtil.getInstance(PortfolioActivity.this).getAdapter(array[0]);
				
				monitorViewHolder.adapter = monitorViewHolder.isCop?    (IndexFuturesInfo.ADAPTER + IndexFuturesInfo.COP) :  bm.getItemRecord(array[0]).itemAdapter;
				monitorViewHolder.itemCode = new TextView(
						PortfolioActivity.this);
				monitorViewHolder.itemCode.setText(array[0]);

				monitorViewHolder.itemName = new TextView(
						PortfolioActivity.this);
				monitorViewHolder.itemValue = new TextView(
						PortfolioActivity.this);
				monitorViewHolder.itemNet = new TextView(
						PortfolioActivity.this);
				monitorViewHolder.itemNetPercentage = new TextView(
						PortfolioActivity.this);
				monitorViewHolder.type = Integer.parseInt(array[1]);

				// 股票
				if (TextUtils.isDigitsOnly(array[0])
						&& StockInfo.ADAPTER
								.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					if (stockInfoItems == null)
					{
						stockInfoItems = new StringBuffer();
						stockInfoItems.append(array[0]);
					}
					else
					{
						stockInfoItems.append(",").append(array[0]);
					}
				}
				else if (monitorViewHolder.isCop)
				{
					if (copItems == null)
					{
						copItems = new StringBuffer();
						copItems.append(array[0]);
					}
					else
					{
						copItems.append(",").append(array[0]);
					}
				}
				// 国际金属
				else if (IntlMetalInfo.ADAPTER
						.equalsIgnoreCase(monitorViewHolder.adapter)
						&& !ForeignExchangeInfo.CODE_TO_NAME
								.containsKey(array[0]))
				{
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}
					if (intlMetalInfoItems == null)
					{
						intlMetalInfoItems = new StringBuffer();
						intlMetalInfoItems.append(array[0]);
						intlMetalInfoNames = new StringBuffer();
						intlMetalInfoNames.append(itemName);
					}
					else
					{
						intlMetalInfoItems.append(",").append(array[0]);
						intlMetalInfoNames.append(",").append(itemName);
					}
					monitorViewHolder.itemName.setText(itemName);
				}// 实时指数期货
				else if (IndexFuturesInfo.adapter_realtime
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						// TODO Auto-generated catch block
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}
					if (indexFuturesInfoRealtimeItems == null)
					{
						indexFuturesInfoRealtimeItems = new StringBuffer(
								array[0]);
						indexFuturesInfoRealtimeNames = new StringBuffer(
								itemName);
					}
					else
					{
						indexFuturesInfoRealtimeItems.append(",")
								.append(array[0]);
						indexFuturesInfoRealtimeNames.append(",")
								.append(itemName);
					}
					monitorViewHolder.itemName
							.setText(itemName == null ? "" : itemName);
				}// 延迟指数期货
				else if (IndexFuturesInfo.adapter_delay
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}
					if (indexFuturesInfoDelayItems == null)
					{
						indexFuturesInfoDelayItems = new StringBuffer(
								array[0]);
						indexFuturesInfoDelayNames = new StringBuffer(
								itemName);
					}
					else
					{
						indexFuturesInfoDelayItems.append(",").append(
								array[0]);
						indexFuturesInfoDelayNames.append(",").append(
								itemName);
					}
					monitorViewHolder.itemName
							.setText(itemName == null ? CommonDefn.DEFAULT_FIELD_VALUE
									: itemName);
				}// 指数
				else if (/* !TextUtils.isDigitsOnly(array[0])&& */IndexInfo.ADAPTER
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}
					if (indexInfoItems == null)
					{
						indexInfoItems = new StringBuffer(array[0]);
						indexInfoNames = new StringBuffer(itemName);
					}
					else
					{
						indexInfoItems.append(",").append(array[0]);
						indexInfoNames.append(",").append(itemName);
					}
					monitorViewHolder.itemName
							.setText(itemName == null ? CommonDefn.DEFAULT_FIELD_VALUE
									: itemName);
				}
				// 国际指数
				else if (WorldIndexInfo.ADAPTER
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}
					if (worldIndexInfoItems == null)
					{
						worldIndexInfoItems = new StringBuffer(array[0]);
						worldIndexInfoNames = new StringBuffer(itemName);
					}
					else
					{
						worldIndexInfoItems.append(",").append(array[0]);
						worldIndexInfoNames.append(",").append(itemName);
					}
					monitorViewHolder.itemName
							.setText(itemName == null ? "" : itemName);

				}
				// 延迟 国际指数
				else if (WorldIndexDelayInfo.ADAPTER
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}

					if (worldIndexDelayInfoItems == null)
					{
						worldIndexDelayInfoItems = new StringBuffer(
								array[0]);
						worldIndexDelayInfoNames = new StringBuffer(
								itemName.length() >= 5 ? itemName
										.substring(0, 5) : itemName);
					}
					else
					{
						worldIndexDelayInfoItems.append(",").append(
								array[0]);
						worldIndexDelayInfoNames.append(",").append(
								itemName.length() >= 5 ? itemName
										.substring(0, 5) : itemName);
					}
					monitorViewHolder.itemName
							.setText(itemName.length() >= 5 ? itemName
									.substring(0, 5) : itemName);
				}// 国际期货
				else if (WorldFuturesInfo.ADAPTER
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}
					if (worldFuturesInfoItems == null)
					{
						worldFuturesInfoItems = new StringBuffer(
								array[0]);
						// WorldIndexDelayInfo_Names = new
						// StringBuffer(itemName.length() >= 5 ?
						// itemName.substring(0, 5): itemName);
					}
					else
					{
						worldFuturesInfoItems.append(",").append(
								array[0]);
						// WorldIndexDelayInfo_Names.append(",").append(itemName.length()
						// >= 5 ? itemName.substring(0,5): itemName);
					}
					monitorViewHolder.itemName
							.setText(itemName.length() >= 5 ? itemName
									.substring(0, 5) : itemName);
				}
				// 外汇
				else if (ForeignExchangeInfo.ADAPTER
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					if (foreignExchangeInfoItems == null)
					{
						foreignExchangeInfoItems = new StringBuffer(
								array[0]);
					}
					else
					{
						foreignExchangeInfoItems.append(",").append(
								array[0]);
					}
				}// 油价
				else if (OilInfo.ADAPTER
						.equalsIgnoreCase(monitorViewHolder.adapter))
				{
					isSubscribedOil = true;
					String itemName;
					try
					{
						// itemName =
						// BookMarkUtil.getInstance(PortfolioActivity.this).getItemName(array[0]);
						itemName = bm.getItemRecord(array[0]).itemName;
					}
					catch (Exception e)
					{
						itemName = CommonDefn.DEFAULT_FIELD_VALUE;
					}
					if (oilInfoItems == null)
					{
						oilInfoItems = new StringBuffer(array[0]);
						oilInfoNames = new StringBuffer(itemName);
					}
					else
					{
						oilInfoItems.append(",").append(array[0]);
						oilInfoNames.append(",").append(itemName);
					}
				}
				_monitorList.add(monitorViewHolder);

			}

			try
			{
				// 股票
				if (stockInfoItems != null)
				{
					if (_callbackHandler00 == null)
					{
						_callbackHandler00 = new CallbackHandlerOnStock();
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							StockInfo.ADAPTER);
					for (String item : stockInfoItems.toString().split(
							","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : StockInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_0);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}

				// COP
				if (copItems != null)
				{
					if (_callbackHandler02 == null)
					{
						_callbackHandler02 = new CallbackHandlerOnCOP();
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							IndexFuturesInfo.adapter_realtime);
					
					for (String item : copItems.toString().split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					
					interestItem.AddSubscribeSchema(IndexFuturesInfo.MM);
					interestItem.AddSubscribeSchema(IndexFuturesInfo.COP);
					
					iIdList.add(IDENTIFIER_2);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}

				// 国际金属
				if (intlMetalInfoItems != null)
				{
					if (_callbackHandler01 == null)
					{
						_callbackHandler01 = new CallbackHandlerOnGold(
								/*intlMetalInfoItems*/ intlMetalInfoNames.toString().split(
										","));
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							IntlMetalInfo.ADAPTER);
					for (String item : intlMetalInfoItems.toString()
							.split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : IntlMetalInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_1);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}
				// 延迟指数期货
				if (indexFuturesInfoDelayItems != null)
				{
					if (_callbackHandler03 == null)
					{
						_callbackHandler03 = new CallbackHandlerOnIndexFutures();
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							IndexFuturesInfo.adapter_delay);
					for (String item : indexFuturesInfoDelayItems
							.toString().split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : IndexFuturesInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_3);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}
				// 实时指数期货
				if (indexFuturesInfoRealtimeItems != null)
				{
					if (_callbackHandler03 == null)
					{
						_callbackHandler03 = new CallbackHandlerOnIndexFutures();
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							IndexFuturesInfo.adapter_realtime);
					
					TDStockLog.d(TAG, "size of indexFutures:" +  indexFuturesInfoRealtimeItems
							.toString().split(",").length );
					for (String item : indexFuturesInfoRealtimeItems
							.toString().split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : IndexFuturesInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_3);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}
				// 指数
				if (indexInfoItems != null)
				{
					if (_callbackHandler04_0 == null)
					{
						_callbackHandler04_0 = new LightStreamerHandlerOnIndex(
								indexInfoNames.toString().split(","),
								IndexInfo.ADAPTER);
					}

					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							IndexInfo.ADAPTER);
					for (String item : indexInfoItems.toString().split(
							","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : IndexInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}

					iIdList.add(IDENTIFIER_4_0);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}
				// 国际指数
				if (worldIndexInfoItems != null)
				{
					if (_callbackHandler04_1 == null)
					{
						_callbackHandler04_1 = new LightStreamerHandlerOnIndex(
								worldIndexInfoNames.toString().split(
										","), WorldIndexInfo.ADAPTER);
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							WorldIndexInfo.ADAPTER);
					for (String item : worldIndexInfoItems.toString()
							.split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : WorldIndexInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}

					iIdList.add(IDENTIFIER_4_1);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}
				// 国际期货
				if (worldFuturesInfoItems != null)
				{
					if (_callbackHandler03 == null)
					{
						_callbackHandler03 = new CallbackHandlerOnIndexFutures();
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							WorldFuturesInfo.ADAPTER);
					for (String item : worldFuturesInfoItems.toString()
							.split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : WorldFuturesInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_3);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
					TDStockLog.d(TAG, "worldIndexFutures items is ready for subscribtion, and items is:" + worldFuturesInfoItems.toString());
					
				}
				// 延迟 国际指数
				if (worldIndexDelayInfoItems != null)
				{
					if (_callbackHandler04_2 == null)
					{
						_callbackHandler04_2 = new LightStreamerHandlerOnIndex(
								worldIndexDelayInfoNames.toString()
										.split(","),
								WorldIndexDelayInfo.ADAPTER);
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							WorldIndexDelayInfo.ADAPTER);
					for (String item : worldIndexDelayInfoItems
							.toString().split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : WorldIndexDelayInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_4_2);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}
				// 外汇
				if (foreignExchangeInfoItems != null)
				{
					if (_callbackHandler05 == null)
					{
						_callbackHandler05 = new LightStreamerHandlerOnFX();
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							ForeignExchangeInfo.ADAPTER);
					for (String item : foreignExchangeInfoItems
							.toString().split(","))
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : ForeignExchangeInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_5);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}
				// 油价
				if (isSubscribedOil)
				{
					if (_callbackHandler06 == null)
					{
						_callbackHandler06 = new LightStreamerHandlerOnOil();
					}
					LS_SubscriptionItem interestItem = new LS_SubscriptionItem(
							OilInfo.ADAPTER);
					for (String item : OilInfo.SUBSCRIBE_ITEMS_CODE)
					{
						interestItem.AddSubscribeItem(item);
					}
					for (String field : OilInfo.MONITOR_FIELDS)
					{
						interestItem.AddSubscribeSchema(field);
					}
					iIdList.add(IDENTIFIER_6);
					iItemList.add(interestItem);
					iResponseList.add(PortfolioActivity.this);
				}

				LightStreamerSubscribeItemsInBatch(iIdList, iItemList,
						iResponseList);
			}

			catch (Exception e)
			{
				// TODO Auto-generated catch block
				// e.printStackTrace();
				handleLightStreamerException(e);
			}

		}

	}
	
	

}
